Class: Depdump::Registry::Tree
- Inherits:
-
Object
- Object
- Depdump::Registry::Tree
- Defined in:
- lib/depdump/registry/tree.rb,
lib/depdump/registry/tree/node.rb,
lib/depdump/registry/tree/relation.rb
Defined Under Namespace
Instance Method Summary collapse
- #each_node ⇒ Object
- #find_or_create_node(namespaces, parent) ⇒ Object
- #resolve(partial_namespaces, entry_node) ⇒ Object
- #root ⇒ Object
Instance Method Details
#each_node ⇒ Object
21 22 23 24 |
# File 'lib/depdump/registry/tree.rb', line 21 def each_node return unless block_given? root.each { |node| yield node } end |
#find_or_create_node(namespaces, parent) ⇒ Object
11 12 13 14 15 16 17 18 19 |
# File 'lib/depdump/registry/tree.rb', line 11 def find_or_create_node(namespaces, parent) # TODO: could be cached rather than search everytime registered = root.detect { |node| namespaces == node.namespaces } return registered if registered Node.new(namespaces: namespaces, parent: parent).tap { |n| parent.children << n } end |
#resolve(partial_namespaces, entry_node) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/depdump/registry/tree.rb', line 26 def resolve(partial_namespaces, entry_node) current_node = entry_node resolved_node = nil while current_node && resolved_node.nil? resolved_node = current_node.dig(partial_namespaces) current_node = current_node&.parent end resolved_node end |