Class: JsonRefs::Dereferencer

Inherits:
Object
  • Object
show all
Defined in:
lib/json_refs.rb

Instance Method Summary collapse

Constructor Details

#initialize(doc, options = {}) ⇒ Dereferencer

Returns a new instance of Dereferencer.



14
15
16
17
# File 'lib/json_refs.rb', line 14

def initialize(doc, options = {})
  @doc = doc
  @options = options
end

Instance Method Details

#call(doc = @doc, keys = []) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/json_refs.rb', line 19

def call(doc = @doc, keys = [])
  if doc.is_a?(Array)
    doc.each_with_index do |value, idx|
      call(value, keys + [idx])
    end
  elsif doc.is_a?(Hash)
    if doc.has_key?('$ref')
      dereference(keys, doc['$ref'])
    else
      doc.each do |key, value|
        call(value, keys + [key])
      end
    end
  end
  doc
end