class Skeleton::Graph

Public Class Methods

new() click to toggle source
# File lib/skeleton/graph.rb, line 9
def initialize
  @dep = Hash.new { |h,k| h[k] = Set.new }
end

Public Instance Methods

each() { |base, name| ... } click to toggle source

Iterate over each of the nodes in this graph with their edge

@return [void]

# File lib/skeleton/graph.rb, line 26
def each(&block)
  @dep.each do |base, set|
    set.each do |name|
      yield(base, name) if block
    end
  end
end
each_dependent_for(base) { |dependent| ... } click to toggle source
# File lib/skeleton/graph.rb, line 46
def each_dependent_for(base, &block)
  each_strongly_connected_component_from(base) do |dependent, _|
    yield(dependent)
  end
end
register(base, *list) click to toggle source

Register a dependency

@param base [Object] the base object @param list [Object,Array] list of dependents

# File lib/skeleton/graph.rb, line 17
def register(base, *list)
  dependents = Array(list).flatten
  @dep[base] ||= Set.new
  @dep[base].merge(dependents)
end
to_set() click to toggle source

Takes all of the nodes in this graph and creates a set with them

@return [Set]

# File lib/skeleton/graph.rb, line 37
def to_set
  set = Set.new
  @dep.each do |base, deps|
    set.add(base)
    set.merge(deps)
  end
  set
end
tsort_each_child(node, &block) click to toggle source
# File lib/skeleton/graph.rb, line 52
def tsort_each_child(node, &block)
  @dep[node].each(&block)
end