Module: Wayfarer::Parsing

Defined in:
lib/wayfarer/parsing.rb,
lib/wayfarer/parsing/xml.rb,
lib/wayfarer/parsing/json.rb

Defined Under Namespace

Modules: JSON, XML

Class Attribute Summary collapse

Class Attribute Details

.registryHash (readonly)

Returns Mapping of Content-Type to parser.

Returns:

  • (Hash)

    Mapping of Content-Type to parser.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/wayfarer/parsing.rb', line 7

module Parsing
  # @!visibility private
  FALLBACK_CONTENT_TYPE = "application/octet-stream"

  mattr_accessor :registry, default: { "application/json" => JSON,
                                       "text/html" => [XML, :html],
                                       "application/xml" => [XML, :xml] }

module_function

  # @!visibility private
  def parse(body, content_type = FALLBACK_CONTENT_TYPE)
    parser, args = registry[content_type] || return

    parser.parse(body, *args)
  end
end