Class: JSONRef

Inherits:
Object
  • Object
show all
Defined in:
lib/json-ref.rb

Constant Summary collapse

VERSION =
'0.1.0'

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(document) ⇒ JSONRef

Returns a new instance of JSONRef.



5
6
7
# File 'lib/json-ref.rb', line 5

def initialize(document)
  @document = document
end

Class Method Details

.expand(document) ⇒ Object



17
18
19
# File 'lib/json-ref.rb', line 17

def self.expand(document)
  self.new(document).expand
end

Instance Method Details

#expandObject



9
10
11
12
13
14
15
# File 'lib/json-ref.rb', line 9

def expand
  @document.each do |k,v|
    if v.is_a?(Hash) && v.has_key?('$ref')
      @document[k] = split_path(v['$ref']).inject(@document) { |doc, item| doc[item] }
    end
  end
end