Class: RFacter::Core::DirectedGraph Private

Inherits:
Hash
  • Object
show all
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

See Also:

Since:

  • 0.1.0

Defined Under Namespace

Classes: CycleError, MissingVertex

Instance Method Summary collapse

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.

Returns:

  • (Boolean)

Since:

  • 0.1.0



17
18
19
# File 'lib/rfacter/core/directed_graph.rb', line 17

def acyclic?
  cycles.empty?
end

#cyclesObject

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.

Since:

  • 0.1.0



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

#tsortObject

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.

Since:

  • 0.1.0



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.

Since:

  • 0.1.0



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