Class: LegacyFacter::Core::DirectedGraph
- Inherits:
-
Hash
- Object
- Hash
- LegacyFacter::Core::DirectedGraph
show all
- Includes:
- TSort
- Defined in:
- lib/facter/custom_facts/core/directed_graph.rb
Defined Under Namespace
Classes: CycleError, MissingVertex
Instance Method Summary
collapse
Instance Method Details
#acyclic? ⇒ Boolean
11
12
13
|
# File 'lib/facter/custom_facts/core/directed_graph.rb', line 11
def acyclic?
cycles.empty?
end
|
#cycles ⇒ Object
15
16
17
18
19
20
21
|
# File 'lib/facter/custom_facts/core/directed_graph.rb', line 15
def cycles
cycles = []
each_strongly_connected_component do |component|
cycles << component if component.size > 1
end
cycles
end
|
#tsort ⇒ Object
29
30
31
32
33
34
35
36
37
38
39
|
# File 'lib/facter/custom_facts/core/directed_graph.rb', line 29
def tsort
missing = Set.new(values.flatten) - Set.new(keys)
unless 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, &block) ⇒ Object
25
26
27
|
# File 'lib/facter/custom_facts/core/directed_graph.rb', line 25
def tsort_each_child(node, &block)
fetch(node, []).each(&block)
end
|