Class: Argo::Dereferencer
- Inherits:
-
Object
- Object
- Argo::Dereferencer
- Defined in:
- lib/argo/dereferencer.rb
Instance Method Summary collapse
- #dereference(hash) ⇒ Object
-
#initialize(&block) ⇒ Dereferencer
constructor
A new instance of Dereferencer.
- #reference?(hash) ⇒ Boolean
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
22 23 24 |
# File 'lib/argo/dereferencer.rb', line 22 def reference?(hash) hash.key?('$ref') end |