class Rack::App::Payload::Parser::Builder

Public Class Methods

new() click to toggle source
# File lib/rack/app/payload/parser/builder.rb, line 5
def initialize
  @content_type__parsers = Hash.new(Rack::App::Payload::Parser::DEFAULT_PARSER)
end

Public Instance Methods

accept(*formats) click to toggle source
# File lib/rack/app/payload/parser/builder.rb, line 18
def accept(*formats)
  Rack::App::Payload::Parser::Builder::Formats.accept(self, *formats)
end
merge!(parser_builder) click to toggle source
# File lib/rack/app/payload/parser/builder.rb, line 41
def merge!(parser_builder)
  raise unless parser_builder.is_a?(self.class)
  @content_type__parsers.merge!(parser_builder.instance_variable_get(:@content_type__parsers))
  self
end
on(content_type, &parser) click to toggle source
# File lib/rack/app/payload/parser/builder.rb, line 13
def on(content_type, &parser)
  @content_type__parsers[content_type]= parser
  self
end
on_unknown_media_types(&parser) click to toggle source
# File lib/rack/app/payload/parser/builder.rb, line 22
def on_unknown_media_types(&parser)
  @content_type__parsers = Hash.new(parser).merge(@content_type__parsers)
end
reject_unsupported_media_types() click to toggle source
# File lib/rack/app/payload/parser/builder.rb, line 26
def reject_unsupported_media_types
  reject = proc do |io|
    rr = Rack::Response.new
    rr.status = 415
    rr.write("Unsupported Media Type")
    rr.write("Accepted content-types:")
    @content_type__parsers.each do |content_type, _|
      rr.write(content_type.to_s)
    end
    throw(:rack_response, rr)
  end
  @content_type__parsers = Hash.new(reject).merge(@content_type__parsers)
  nil
end
to_parser() click to toggle source
# File lib/rack/app/payload/parser/builder.rb, line 9
def to_parser
  Rack::App::Payload::Parser.new(@content_type__parsers.dup)
end