Class: Argo::Dereferencer

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

Instance Method Summary collapse

Constructor Details

#initialize(&block) ⇒ Dereferencer

Returns a new instance of Dereferencer.



5
6
7
# File 'lib/argo/dereferencer.rb', line 5

def initialize(&block)
  @block = block
end

Instance Method Details

#dereference(hash) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/argo/dereferencer.rb', line 9

def dereference(hash)
  path = hash.fetch('$ref')
  fragments = path.split(/\//)
  unless fragments[0] == '#'
    raise "Can't dereference non-root-anchored path '#{path}'"
  end
  DeferredObject.new {
    fragments.drop(1).inject(@block.call) { |schema, fragment|
      schema.schemas.fetch(fragment)
    }
  }
end

#reference?(hash) ⇒ Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/argo/dereferencer.rb', line 22

def reference?(hash)
  hash.key?('$ref')
end