Class: ForemanMaintain::DependencyGraph
- Inherits:
-
Object
- Object
- ForemanMaintain::DependencyGraph
- Includes:
- TSort
- Defined in:
- lib/foreman_maintain/dependency_graph.rb
Instance Attribute Summary collapse
-
#collection ⇒ Object
readonly
Returns the value of attribute collection.
-
#graph ⇒ Object
readonly
Returns the value of attribute graph.
-
#labels ⇒ Object
readonly
Returns the value of attribute labels.
Class Method Summary collapse
Instance Method Summary collapse
- #add_to_graph(key, dependencies = []) ⇒ Object
-
#initialize(collection) ⇒ DependencyGraph
constructor
A new instance of DependencyGraph.
- #tsort_each_child(node, &block) ⇒ Object
- #tsort_each_node(&block) ⇒ Object
Constructor Details
#initialize(collection) ⇒ DependencyGraph
Returns a new instance of DependencyGraph.
13 14 15 16 17 18 |
# File 'lib/foreman_maintain/dependency_graph.rb', line 13 def initialize(collection) @graph = Hash.new([]) @collection = collection @steps_by_labels = @collection.group_by(&:label) generate_label_graph end |
Instance Attribute Details
#collection ⇒ Object (readonly)
Returns the value of attribute collection.
7 8 9 |
# File 'lib/foreman_maintain/dependency_graph.rb', line 7 def collection @collection end |
#graph ⇒ Object (readonly)
Returns the value of attribute graph.
7 8 9 |
# File 'lib/foreman_maintain/dependency_graph.rb', line 7 def graph @graph end |
#labels ⇒ Object (readonly)
Returns the value of attribute labels.
7 8 9 |
# File 'lib/foreman_maintain/dependency_graph.rb', line 7 def labels @labels end |
Class Method Details
.sort(collection) ⇒ Object
9 10 11 |
# File 'lib/foreman_maintain/dependency_graph.rb', line 9 def self.sort(collection) new(collection).tsort.map(&:ensure_instance) end |
Instance Method Details
#add_to_graph(key, dependencies = []) ⇒ Object
20 21 22 23 24 |
# File 'lib/foreman_maintain/dependency_graph.rb', line 20 def add_to_graph(key, dependencies = []) return unless key graph[key] = dependencies end |
#tsort_each_child(node, &block) ⇒ Object
30 31 32 |
# File 'lib/foreman_maintain/dependency_graph.rb', line 30 def tsort_each_child(node, &block) graph.fetch(node).each(&block) end |
#tsort_each_node(&block) ⇒ Object
26 27 28 |
# File 'lib/foreman_maintain/dependency_graph.rb', line 26 def tsort_each_node(&block) @collection.each(&block) end |