Class: RosettAi::Composition::CircularDependencyDetector

Inherits:
Object
  • Object
show all
Defined in:
lib/rosett_ai/composition/circular_dependency_detector.rb

Overview

Detects circular dependencies in behaviour depends_on graphs. Uses depth-first search to find cycles and reports the full cycle path for debugging.

Instance Method Summary collapse

Instance Method Details

#detect(graph) ⇒ Array<String>?

Checks a dependency graph for cycles.

Parameters:

  • graph (Hash{String => Array<String>})

    adjacency list mapping behaviour names to their dependencies

Returns:

  • (Array<String>, nil)

    cycle path if found, nil otherwise



17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/rosett_ai/composition/circular_dependency_detector.rb', line 17

def detect(graph)
  visited = {}
  stack = {}

  graph.each_key do |node|
    next if visited[node]

    cycle = dfs(node, graph, visited, stack, [])
    return cycle if cycle
  end

  nil
end