Class: Really::DependencyGraph
- Includes:
- TSort
- Defined in:
- lib/really/dependency_graph.rb
Instance Method Summary collapse
- #add(node) ⇒ Object
-
#initialize(node_pool = {}) ⇒ DependencyGraph
constructor
A new instance of DependencyGraph.
- #tsort_each_child(node, &block) ⇒ Object
- #tsort_each_node(&block) ⇒ Object
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 |