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.



57
58
59
60
61
# File 'lib/schemurai/schema_graph.rb', line 57

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

Instance Attribute Details

#root ⇒ Object (readonly)

Returns the value of attribute root.



55
56
57
# File 'lib/schemurai/schema_graph.rb', line 55

def root
  @root
end

#uri ⇒ Object (readonly)

Returns the value of attribute uri.



55
56
57
# File 'lib/schemurai/schema_graph.rb', line 55

def uri
  @uri
end

Instance Method Details

#add(node) ⇒ Object



63
64
65
66
# File 'lib/schemurai/schema_graph.rb', line 63

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



68
69
70
71
72
# File 'lib/schemurai/schema_graph.rb', line 68

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

  @nodes&.[](pointer)
end

#nodes ⇒ Object



74
75
76
# File 'lib/schemurai/schema_graph.rb', line 74

def nodes
  @nodes || EMPTY_NODES
end