Class: Really::DependencyGraph

Inherits:
Object
  • Object
show all
Includes:
TSort
Defined in:
lib/really/dependency_graph.rb

Instance Method Summary collapse

Constructor Details

#initialize(node_pool = {}) ⇒ DependencyGraph

Returns a new instance of DependencyGraph.



7
8
9
10
# File 'lib/really/dependency_graph.rb', line 7

def initialize(node_pool = {})
  @node_pool = node_pool
  @nodes = []
end

Instance Method Details

#add(node) ⇒ Object



12
13
14
# File 'lib/really/dependency_graph.rb', line 12

def add(node)
  @nodes << node
end

#tsort_each_child(node, &block) ⇒ Object



22
23
24
25
26
27
28
# File 'lib/really/dependency_graph.rb', line 22

def tsort_each_child(node, &block)
  @node_pool[node.name].dependencies.each do |dependency_name|
    node = @node_pool[dependency_name]
    raise "Dependency '#{dependency_name}' does not exist." if node.nil?
    block.call node
  end
end

#tsort_each_node(&block) ⇒ Object



18
19
20
# File 'lib/really/dependency_graph.rb', line 18

def tsort_each_node(&block)
  @nodes.each &block
end