Class: Pakyow::Connection::MultipartParser
- Inherits:
-
Object
- Object
- Pakyow::Connection::MultipartParser
- Defined in:
- lib/pakyow/connection/multipart_parser.rb
Defined Under Namespace
Classes: LimitExceeded, ParseError
Constant Summary collapse
- DEFAULT_MULTIPART_LIMIT =
100
Instance Attribute Summary collapse
-
#values ⇒ Object
readonly
Returns the value of attribute values.
Instance Method Summary collapse
-
#initialize(params, boundary:) ⇒ MultipartParser
constructor
A new instance of MultipartParser.
- #parse(input) ⇒ Object
Constructor Details
#initialize(params, boundary:) ⇒ MultipartParser
Returns a new instance of MultipartParser.
20 21 22 23 24 25 26 27 |
# File 'lib/pakyow/connection/multipart_parser.rb', line 20 def initialize(params, boundary:) @params, @boundary = params, boundary.to_s.gsub(/[\"\']/, "") @reader = ::MultipartParser::Reader.new(@boundary) @reader.on_part(&method(:on_part)) @reader.on_error(&method(:on_error)) @values = [] @size = 0 end |
Instance Attribute Details
#values ⇒ Object (readonly)
Returns the value of attribute values.
18 19 20 |
# File 'lib/pakyow/connection/multipart_parser.rb', line 18 def values @values end |
Instance Method Details
#parse(input) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/pakyow/connection/multipart_parser.rb', line 29 def parse(input) while data = input.read @reader.write(data) end finalize @params rescue StandardError => error ensure_closed if error.is_a?(LimitExceeded) raise error else raise ParseError.build(error) end end |