Module: Algorithmable::Cups::CircularDependencies

Defined in:
lib/algorithmable/cups/circular_dependencies.rb

Instance Method Summary collapse

Instance Method Details

#dfs(item, dependencies, visited, &block) ⇒ Object


12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/algorithmable/cups/circular_dependencies.rb', line 12

def dfs(item, dependencies, visited, &block)
  next_items = dependencies[item]
  return [] unless next_items
  visited << item

  next_items.each do |dep|
    if visited.include? dep
      yield item, dep if block_given?
      next
    end
    dfs(dep, dependencies, visited, &block)
  end
end

#lib_dependencies(item, dependencies) ⇒ Object


4
5
6
7
8
9
10
# File 'lib/algorithmable/cups/circular_dependencies.rb', line 4

def lib_dependencies(item, dependencies)
  visited = []
  dfs(item, dependencies, visited) do |entry, dep|
    puts "circular dependency: #{entry} <=> #{dep}"
  end
  visited
end