Module: ActsAsGraph
- Defined in:
- lib/acts_as_graph.rb,
lib/acts_as_graph/dag.rb,
lib/acts_as_graph/version.rb
Defined Under Namespace
Modules: ClassMethods
Classes: Dag
Constant Summary
collapse
- VERSION =
'0.0.3'
Class Method Summary
collapse
Instance Method Summary
collapse
Class Method Details
.included(base) ⇒ Object
5
6
7
|
# File 'lib/acts_as_graph.rb', line 5
def self.included base
base.extend ClassMethods
end
|
Instance Method Details
#child_vertices ⇒ Object
54
55
56
|
# File 'lib/acts_as_graph.rb', line 54
def child_vertices
self.send children_method_name
end
|
#collect_child_vertices(vertices_found, starting_vertice: nil) ⇒ Object
31
32
33
34
35
36
37
|
# File 'lib/acts_as_graph.rb', line 31
def collect_child_vertices vertices_found, starting_vertice: nil
child_vertices.each do |child_vertice|
next if vertices_found.include?(child_vertice) || child_vertice == starting_vertice
vertices_found << child_vertice
child_vertice.collect_child_vertices vertices_found, starting_vertice: starting_vertice if child_vertice.respond_to?(:collect_child_vertices)
end
end
|
#descendant_vertices ⇒ Object
25
26
27
28
29
|
# File 'lib/acts_as_graph.rb', line 25
def descendant_vertices
vertices_found = []
collect_child_vertices vertices_found, starting_vertice: self
vertices_found
end
|
#has_circular_reference? ⇒ Boolean
39
40
41
42
43
44
|
# File 'lib/acts_as_graph.rb', line 39
def has_circular_reference?
child_vertices.any? do |child_vertice|
path = [self, child_vertice]
child_vertice.has_circular_reference_in_path?(path) if child_vertice.respond_to?(:has_circular_reference_in_path?)
end
end
|
#has_circular_reference_in_path?(path) ⇒ Boolean
46
47
48
49
50
51
52
|
# File 'lib/acts_as_graph.rb', line 46
def has_circular_reference_in_path? path
child_vertices.any? do |child_vertice|
return true if path.include?(child_vertice)
next_path = path + [child_vertice]
child_vertice.has_circular_reference_in_path?(next_path) if child_vertice.respond_to?(:has_circular_reference_in_path?)
end
end
|