module ActsAsGraph

Constants

VERSION

Public Class Methods

included(base) click to toggle source
# File lib/acts_as_graph.rb, line 5
def self.included base
  base.extend ClassMethods
end

Public Instance Methods

child_vertices() click to toggle source
# 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) click to toggle source
# 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() click to toggle source
# 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?() click to toggle source
# 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) click to toggle source
# 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

Private Instance Methods

children_method_name() click to toggle source
# File lib/acts_as_graph.rb, line 60
def children_method_name
  self.class.children_method_name
end