class Depdump::Registry::Tree::Node

Attributes

children[R]
namespaces[R]
parent[R]
relations[R]

Public Class Methods

new(namespaces: [], parent:) click to toggle source
# File lib/depdump/registry/tree/node.rb, line 9
def initialize(namespaces: [], parent:)
  @namespaces = namespaces
  @relations = []
  @children = []
  @parent = parent
end

Public Instance Methods

create_relation(reference, search_entry_node: nil) click to toggle source
# 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) click to toggle source
# 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() { |child| ... } click to toggle source
# 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) click to toggle source
# File lib/depdump/registry/tree/node.rb, line 30
def eql?(other)
  namespaces == other.namespaces
end
hash() click to toggle source
# File lib/depdump/registry/tree/node.rb, line 26
def hash
  namespaces.hash
end
root?() click to toggle source
# File lib/depdump/registry/tree/node.rb, line 22
def root?
  parent.nil?
end