Module: Grape::Formatter::Base

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

Constant Summary collapse

FORMATTERS =
{
  json: Grape::Formatter::Json,
  jsonapi: 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



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

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



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

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