class Gemlist::SpecNode

Attributes

children[R]
content[R]
name[R]
parent[RW]

Public Class Methods

new(name, content) click to toggle source
# File lib/gemlist/spec_node.rb, line 8
def initialize(name, content)
  @name     = name
  @content  = content
  @children = []
  @parent   = nil
end

Public Instance Methods

<<(node) click to toggle source
# File lib/gemlist/spec_node.rb, line 15
def <<(node)
  @children << node
  node.parent = self
  node
end
depth_first_children_first() click to toggle source
# File lib/gemlist/spec_node.rb, line 47
def depth_first_children_first
  sorted_children = children.sort_by(&:total_dependency_count)
  parent          = self

  Enumerator.new do |yielder|
    sorted_children.each do |child|
      child.depth_first_children_first.each do |node|
        yielder << node
      end
    end

    yielder << parent
  end
end
descends_from?(*dependencies) click to toggle source
# File lib/gemlist/spec_node.rb, line 66
def descends_from?(*dependencies)
  !root? &&
    dependencies.map(&:name).include?(lineage.first.name)
end
each() { |current| ... } click to toggle source
# File lib/gemlist/spec_node.rb, line 21
def each(&block)
  return to_enum unless block_given?

  unvisited = [self]

  until unvisited.empty?
    current = unvisited.shift

    if current
      yield current

      unvisited.unshift(*current.children)
    end
  end

  return self if block_given?
end
lineage() click to toggle source
# File lib/gemlist/spec_node.rb, line 62
def lineage
  [self, *parentage].reverse.reject(&:root?)
end
parentage() click to toggle source
# File lib/gemlist/spec_node.rb, line 71
def parentage
  return [] if root?

  [parent] + parent.parentage
end
root?() click to toggle source
# File lib/gemlist/spec_node.rb, line 77
def root?
  parent.nil?
end
size() click to toggle source
# File lib/gemlist/spec_node.rb, line 43
def size
  to_a.size
end
total_dependency_count() click to toggle source
# File lib/gemlist/spec_node.rb, line 39
def total_dependency_count
  size - 1
end