Class: Rack::App::Payload::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/rack/app/payload/parser.rb

Constant Summary collapse

DEFAULT_PARSER =
proc { |io| io.read }

Instance Method Summary collapse

Constructor Details

#initialize(content_type__parsers = {}) ⇒ Parser

Returns a new instance of Parser.



8
9
10
11
# File 'lib/rack/app/payload/parser.rb', line 8

def initialize(content_type__parsers = {})
  raise unless content_type__parsers.is_a?(Hash)
  @content_type__parsers = content_type__parsers
end

Instance Method Details

#parse_env(env) ⇒ Object



17
18
19
20
# File 'lib/rack/app/payload/parser.rb', line 17

def parse_env(env)
  request = Rack::Request.new(env)
  parse_io(request.content_type, request.body)
end

#parse_io(content_type, io) ⇒ Object



13
14
15
# File 'lib/rack/app/payload/parser.rb', line 13

def parse_io(content_type, io)
  parser_for(content_type.to_s).call(io)
end

#parse_string(content_type, str) ⇒ Object



22
23
24
# File 'lib/rack/app/payload/parser.rb', line 22

def parse_string(content_type, str)
  parse_io(content_type, StringIO.new(str))
end