Sha256: 3e86a83c6e97a3b5d5ded3877a665c9e65513a9e3be01a439b367c55b5f2f0f0

Contents?: true

Size: 1.21 KB

Versions: 49

Compression:

Stored size: 1.21 KB

Contents

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

  require "rack/app/payload/parser/builder/formats"

  def initialize
    @content_type__parsers = Hash.new(Rack::App::Payload::Parser::DEFAULT_PARSER)
  end

  def to_parser
    Rack::App::Payload::Parser.new(@content_type__parsers.dup)
  end

  def on(content_type, &parser)
    @content_type__parsers[content_type]= parser
    self
  end

  def accept(*formats)
    Rack::App::Payload::Parser::Builder::Formats.accept(self, *formats)
  end

  def on_unknown_media_types(&parser)
    @content_type__parsers = Hash.new(parser).merge(@content_type__parsers)
  end

  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

  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

end

Version data entries

49 entries across 49 versions & 2 rubygems

Version Path
rack-app-11.0.2 lib/rack/app/payload/parser/builder.rb
rack-app-11.0.1 lib/rack/app/payload/parser/builder.rb
rack-app-11.0.0 lib/rack/app/payload/parser/builder.rb
rack-app-10.0.0 lib/rack/app/payload/parser/builder.rb
rack-app-9.0.0 lib/rack/app/payload/parser/builder.rb
rack-app-8.1.0 lib/rack/app/payload/parser/builder.rb
rack-app-8.0.1 lib/rack/app/payload/parser/builder.rb
rack-app-8.0.0 lib/rack/app/payload/parser/builder.rb
mountapi-0.11.1 vendor/bundle/ruby/2.7.0/gems/rack-app-7.7.0/lib/rack/app/payload/parser/builder.rb
rack-app-7.7.0 lib/rack/app/payload/parser/builder.rb
rack-app-7.6.5 lib/rack/app/payload/parser/builder.rb
rack-app-7.6.4 lib/rack/app/payload/parser/builder.rb
rack-app-7.6.3 lib/rack/app/payload/parser/builder.rb
rack-app-7.6.2 lib/rack/app/payload/parser/builder.rb
rack-app-7.6.1 lib/rack/app/payload/parser/builder.rb
rack-app-7.6.0 lib/rack/app/payload/parser/builder.rb
rack-app-7.5.2 lib/rack/app/payload/parser/builder.rb
rack-app-7.5.1 lib/rack/app/payload/parser/builder.rb
rack-app-7.5.0 lib/rack/app/payload/parser/builder.rb
rack-app-7.4.0 lib/rack/app/payload/parser/builder.rb