class Rack::App::Serializer::FormatsBuilder

Public Class Methods

new() click to toggle source
# File lib/rack/app/serializer/formats_builder.rb, line 3
def initialize
  @formatters = {}
  @content_types = {}
  @default_formatter = lambda { |o| o.to_s }
  @default_content_type = nil
end

Public Instance Methods

default(content_type=nil, &block) click to toggle source
# File lib/rack/app/serializer/formats_builder.rb, line 18
def default(content_type=nil, &block)
  @default_content_type = content_type if content_type
  @default_formatter = block if block
  self
end
merge!(formats_builder) click to toggle source
# File lib/rack/app/serializer/formats_builder.rb, line 33
def merge!(formats_builder)
  @formatters.merge!(formats_builder.instance_variable_get(:@formatters))
  @default_formatter = formats_builder.instance_variable_get(:@default_formatter)
  self
end
on(extname, response_content_type, &formatter) click to toggle source
# File lib/rack/app/serializer/formats_builder.rb, line 10
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
to_serializer() click to toggle source
# File lib/rack/app/serializer/formats_builder.rb, line 24
def to_serializer
  Rack::App::Serializer.new(
    :formatters => @formatters,
    :content_types => @content_types,
    :default_formatter => @default_formatter,
    :default_content_type => @default_content_type
  )
end