Class: Moon::DataSerializer::Resolver

Inherits:
Object
  • Object
show all
Defined in:
lib/moon/packages/dataman/data_serializer.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.resolve(data, depth = 0) ⇒ Object


24
25
26
# File 'lib/moon/packages/dataman/data_serializer.rb', line 24

def self.resolve(data, depth = 0)
  new.resolve(data, depth)
end

Instance Method Details

#resolve(data, depth) ⇒ Object


4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/moon/packages/dataman/data_serializer.rb', line 4

def resolve(data, depth)
  case data
  when Array
    data.map do |obj|
      resolve(obj, depth + 1)
    end
  when Hash
    if refname = data['&ref']
      DataLoader.file(refname)
    else
      data.each_with_object({}) do |a, r|
        k, v = *a
        r[k] = resolve(v, depth + 1)
      end
    end
  else
    data
  end
end