Class: RFacter::Core::DirectedGraph Private
- Inherits:
-
Hash
- Object
- Hash
- RFacter::Core::DirectedGraph
- Includes:
- TSort
- Defined in:
- lib/rfacter/core/directed_graph.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Directed graph for sorting aggregate chunk dependencies
Defined Under Namespace
Classes: CycleError, MissingVertex
Instance Method Summary collapse
- #acyclic? ⇒ Boolean private
- #cycles ⇒ Object private
- #tsort ⇒ Object private
- #tsort_each_child(node) ⇒ Object private
Instance Method Details
#acyclic? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
17 18 19 |
# File 'lib/rfacter/core/directed_graph.rb', line 17 def acyclic? cycles.empty? end |
#cycles ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
21 22 23 24 25 26 27 |
# File 'lib/rfacter/core/directed_graph.rb', line 21 def cycles cycles = [] each_strongly_connected_component do |component| cycles << component if component.size > 1 end cycles end |
#tsort ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/rfacter/core/directed_graph.rb', line 37 def tsort missing = Set.new(self.values.flatten) - Set.new(self.keys) if not missing.empty? raise MissingVertex, "Cannot sort elements; cannot depend on missing elements #{missing.to_a}" end super rescue TSort::Cyclic raise CycleError, "Cannot sort elements; found the following cycles: #{cycles.inspect}" end |
#tsort_each_child(node) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
31 32 33 34 35 |
# File 'lib/rfacter/core/directed_graph.rb', line 31 def tsort_each_child(node) fetch(node, []).each do |child| yield child end end |