Sha256: b9dbb48fe6ae3f2f0b98d7b46d9581c3f6e3ba5d8f9462029874220ec6f15fc8

Contents?: true

Size: 1.03 KB

Versions: 54

Compression:

Stored size: 1.03 KB

Contents

class Rack::App::Serializer::FormatsBuilder

  def initialize
    @formatters = {}
    @content_types = {}
    @default_formatter = lambda { |o| o.to_s }
    @default_content_type = nil
  end

  def on(extname, response_content_type, &formatter)
    format = String(extname).downcase
    extension = (format[0,1] == '.' ? format : ".#{format}")
    @formatters[extension]= formatter
    @content_types[extension]= response_content_type
    self
  end

  def default(content_type=nil, &block)
    @default_content_type = content_type if content_type
    @default_formatter = block if block
    self
  end

  def to_serializer
    Rack::App::Serializer.new(
      :formatters => @formatters,
      :content_types => @content_types,
      :default_formatter => @default_formatter,
      :default_content_type => @default_content_type
    )
  end

  def merge!(formats_builder)
    @formatters.merge!(formats_builder.instance_variable_get(:@formatters))
    @default_formatter = formats_builder.instance_variable_get(:@default_formatter)
    self
  end

end

Version data entries

54 entries across 54 versions & 2 rubygems

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