Class: RFacter::Core::DirectedGraph
  
  
  
  
  
    - Inherits:
- 
      Hash
      
        
          - Object
- Hash
- RFacter::Core::DirectedGraph
 show all
      - Includes:
- TSort
    - Defined in:
- lib/rfacter/core/directed_graph.rb
 
Defined Under Namespace
  
    
  
    
      Classes: CycleError, MissingVertex
    
  
  
    
      Instance Method Summary
      collapse
    
    
  
  
  
  
    Instance Method Details
    
      
  
  
    #acyclic?  ⇒ Boolean 
  
  
  
  
    | 
11
12
13 | # File 'lib/rfacter/core/directed_graph.rb', line 11
def acyclic?
  cycles.empty?
end | 
 
    
      
  
  
    #cycles  ⇒ Object 
  
  
  
  
    | 
15
16
17
18
19
20
21 | # File 'lib/rfacter/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 
  
  
  
  
    | 
31
32
33
34
35
36
37
38
39
40
41
42 | # File 'lib/rfacter/core/directed_graph.rb', line 31
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 
  
  
  
  
    | 
25
26
27
28
29 | # File 'lib/rfacter/core/directed_graph.rb', line 25
def tsort_each_child(node)
  fetch(node, []).each do |child|
    yield child
  end
end |