Module: Grape::Parser

Extended by:
ActiveSupport::Autoload, Util::Registrable
Defined in:
lib/grape.rb,
lib/grape/parser.rb,
lib/grape/parser/xml.rb,
lib/grape/parser/json.rb

Defined Under Namespace

Modules: Json, Xml

Class Method Summary collapse

Methods included from Util::Registrable

default_elements, register

Class Method Details

.builtin_parsersObject



8
9
10
11
12
13
14
# File 'lib/grape/parser.rb', line 8

def builtin_parsers
  @builtin_parsers ||= {
    json: Grape::Parser::Json,
    jsonapi: Grape::Parser::Json,
    xml: Grape::Parser::Xml
  }
end

.parser_for(api_format, **options) ⇒ Object



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

def parser_for(api_format, **options)
  spec = parsers(**options)[api_format]
  case spec
  when nil
    nil
  when Symbol
    method(spec)
  else
    spec
  end
end

.parsers(**options) ⇒ Object



16
17
18
# File 'lib/grape/parser.rb', line 16

def parsers(**options)
  builtin_parsers.merge(default_elements).merge!(options[:parsers] || {})
end