Module: Grape::Formatter::Base

Defined in:
lib/grape/formatter/base.rb

Constant Summary collapse

FORMATTERS =
{
  :json => Grape::Formatter::Json,
  :serializable_hash => Grape::Formatter::SerializableHash,
  :txt => Grape::Formatter::Txt,
  :xml => Grape::Formatter::Xml
}

Class Method Summary collapse

Class Method Details

.formatter_for(api_format, options = {}) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
# File 'lib/grape/formatter/base.rb', line 18

def formatter_for(api_format, options = {})
  spec = formatters(options)[api_format]
  case spec
  when nil
    lambda { |obj, env| obj }
  when Symbol
    method(spec)
  else
    spec
  end
end

.formatters(options) ⇒ Object



14
15
16
# File 'lib/grape/formatter/base.rb', line 14

def formatters(options)
  FORMATTERS.merge(options[:formatters] || {})
end