Class: JsonRefs::Dereferencer

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

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Dereferencer.



20
21
22
23
24
# File 'lib/json_refs.rb', line 20

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

Instance Method Details

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



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/json_refs.rb', line 26

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