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


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

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

.parser_for(api_format, **options) ⇒ Object


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

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


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

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