Module: Restify::Processors::Base::Parsing

Defined in:
lib/restify/processors/base/parsing.rb

Overview

Parses generic data structures into resources

Instance Method Summary collapse

Instance Method Details

#loadObject



12
13
14
# File 'lib/restify/processors/base/parsing.rb', line 12

def load
  parse deserialized_body, root: true
end

#parse(object, root: false) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/restify/processors/base/parsing.rb', line 16

def parse(object, root: false)
  case object
    when Hash
      data      = object.each_with_object({}) {|each, obj| parse_data(each, obj) }
      relations = object.each_with_object({}) {|each, obj| parse_rels(each, obj) }

      Resource.new context,
        data:,
        response: root ? response : nil,
        relations:

    when Array
      object.map {|each| parse(each) }
    else
      object
  end
end