Class: Depdump::Registry::Tree::Node
- Inherits:
-
Object
- Object
- Depdump::Registry::Tree::Node
- Includes:
- Enumerable
- Defined in:
- lib/depdump/registry/tree/node.rb
Instance Attribute Summary collapse
-
#children ⇒ Object
readonly
Returns the value of attribute children.
-
#namespaces ⇒ Object
readonly
Returns the value of attribute namespaces.
-
#parent ⇒ Object
readonly
Returns the value of attribute parent.
-
#relations ⇒ Object
readonly
Returns the value of attribute relations.
Instance Method Summary collapse
- #create_relation(reference, search_entry_node: nil) ⇒ Object
- #dig(partial_namespaces) ⇒ Object
- #each(&block) ⇒ Object
- #eql?(other) ⇒ Boolean
- #hash ⇒ Object
-
#initialize(namespaces: [], parent:) ⇒ Node
constructor
A new instance of Node.
- #root? ⇒ Boolean
Constructor Details
#initialize(namespaces: [], parent:) ⇒ Node
Returns a new instance of Node.
9 10 11 12 13 14 |
# File 'lib/depdump/registry/tree/node.rb', line 9 def initialize(namespaces: [], parent:) @namespaces = namespaces @relations = [] @children = [] @parent = parent end |
Instance Attribute Details
#children ⇒ Object (readonly)
Returns the value of attribute children.
7 8 9 |
# File 'lib/depdump/registry/tree/node.rb', line 7 def children @children end |
#namespaces ⇒ Object (readonly)
Returns the value of attribute namespaces.
7 8 9 |
# File 'lib/depdump/registry/tree/node.rb', line 7 def namespaces @namespaces end |
#parent ⇒ Object (readonly)
Returns the value of attribute parent.
7 8 9 |
# File 'lib/depdump/registry/tree/node.rb', line 7 def parent @parent end |
#relations ⇒ Object (readonly)
Returns the value of attribute relations.
7 8 9 |
# File 'lib/depdump/registry/tree/node.rb', line 7 def relations @relations end |
Instance Method Details
#create_relation(reference, search_entry_node: nil) ⇒ Object
16 17 18 19 20 |
# File 'lib/depdump/registry/tree/node.rb', line 16 def create_relation(reference, search_entry_node: nil) Relation.new(node: self, reference: reference, search_entry_node: search_entry_node).tap { |r| @relations << r } end |
#dig(partial_namespaces) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/depdump/registry/tree/node.rb', line 43 def dig(partial_namespaces) found = nil children.each do |node| exactly_match = node.namespaces.last(partial_namespaces.size) == partial_namespaces found = node and break if exactly_match route_match = node.namespaces.last == partial_namespaces.first if route_match found = node.dig(partial_namespaces[1..-1]) break if found end end found end |
#each(&block) ⇒ Object
34 35 36 37 38 39 40 41 |
# File 'lib/depdump/registry/tree/node.rb', line 34 def each(&block) return unless block_given? children.each do |child| yield child child.each(&block) end end |
#eql?(other) ⇒ Boolean
30 31 32 |
# File 'lib/depdump/registry/tree/node.rb', line 30 def eql?(other) namespaces == other.namespaces end |
#hash ⇒ Object
26 27 28 |
# File 'lib/depdump/registry/tree/node.rb', line 26 def hash namespaces.hash end |
#root? ⇒ Boolean
22 23 24 |
# File 'lib/depdump/registry/tree/node.rb', line 22 def root? parent.nil? end |