class Frill::DependencyGraph::CycleDetecter

Attributes

nodes[R]
visited[R]

Public Class Methods

detect!(nodes) click to toggle source
# File lib/frill/frill.rb, line 107
def self.detect! nodes
  new(nodes).detect!
end
new(nodes) click to toggle source
# File lib/frill/frill.rb, line 111
def initialize nodes
  @nodes = nodes
  @visited = {}
end

Public Instance Methods

detect!() click to toggle source
# File lib/frill/frill.rb, line 116
def detect!
  nodes.values.each do |node|
    fan_out node unless visited[node.label]
  end
end

Private Instance Methods

fan(direction, start_node) click to toggle source
# File lib/frill/frill.rb, line 132
def fan direction, start_node
  current_node = start_node.send direction

  while current_node
    raise Frill::CyclicDependency if visited[current_node.label]
    visited[current_node.label] = true
    current_node = current_node.send direction
  end
end
fan_out(node) click to toggle source
# File lib/frill/frill.rb, line 125
def fan_out node
  visited[node.label] = true

  fan :next, node
  fan :previous, node
end