Class: JsonRefs::Dereferencer
- Inherits:
-
Object
- Object
- JsonRefs::Dereferencer
- Defined in:
- lib/json_refs.rb
Instance Method Summary collapse
- #call(doc = @doc, keys = []) ⇒ Object
-
#initialize(doc) ⇒ Dereferencer
constructor
A new instance of Dereferencer.
Constructor Details
#initialize(doc) ⇒ Dereferencer
Returns a new instance of Dereferencer.
10 11 12 |
# File 'lib/json_refs.rb', line 10 def initialize(doc) @doc = doc end |
Instance Method Details
#call(doc = @doc, keys = []) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/json_refs.rb', line 14 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 |