Class: Schemurai::Internal::SchemaGraph::Resource

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(uri, root) ⇒ Resource

Returns a new instance of Resource.



18
19
20
21
22
# File 'lib/schemurai/schema_graph.rb', line 18

def initialize(uri, root)
  @uri = uri
  @root = root
  @nodes = nil
end

Instance Attribute Details

#rootObject (readonly)

Returns the value of attribute root.



16
17
18
# File 'lib/schemurai/schema_graph.rb', line 16

def root
  @root
end

#uriObject (readonly)

Returns the value of attribute uri.



16
17
18
# File 'lib/schemurai/schema_graph.rb', line 16

def uri
  @uri
end

Instance Method Details

#add(node) ⇒ Object



24
25
26
27
# File 'lib/schemurai/schema_graph.rb', line 24

def add(node)
  (@nodes ||= {})[node.resource_path] = node unless node.equal?(root)
  node.resource = self unless node.resource.equal?(self)
end

#node_at(pointer) ⇒ Object



29
30
31
32
33
# File 'lib/schemurai/schema_graph.rb', line 29

def node_at(pointer)
  return root if pointer.empty?

  @nodes&.[](pointer)
end

#nodesObject



35
36
37
# File 'lib/schemurai/schema_graph.rb', line 35

def nodes
  @nodes || EMPTY_NODES
end