lib/inventory_refresh/graph.rb
def traverse_dependecies(traversed_nodes, starting_node, current_node, edges, dependencies, escalation)
      dependencies.each do |node_edge|
        node = node_edge.first
        traversed_nodes << node
        if traversed_nodes.include?(starting_node)
          if escalation == :exception
            raise "Cycle from #{current_node} to #{node}, starting from #{starting_node} passing #{traversed_nodes}"
          else
            return true
          end
        end
        return true if traverse_dependecies(traversed_nodes, starting_node, node, edges, node_edges(edges, node), escalation)
      end

      false
    end
def traverse_dependecies(traversed_nodes, starting_node, current_node, edges, dependencies, escalation)
      dependencies.each do |node_edge|
        node = node_edge.first
        traversed_nodes << node
        if traversed_nodes.include?(starting_node)
          if escalation == :exception
            raise "Cycle from #{current_node} to #{node}, starting from #{starting_node} passing #{traversed_nodes}"
          else
            return true
          end
        end
        return true if traverse_dependecies(traversed_nodes, starting_node, node, edges, node_edges(edges, node), escalation)
      end

      false
    end
def traverse_dependecies ( traversed_nodes , starting_node , current_node , edges , dependencies , escalation ) dependencies . each do | node_edge | node = node_edge . first traversed_nodes << node if traversed_nodes . include? ( starting_node ) if escalation == :exception raise "Cycle from #{current_node} to #{node}, starting from #{starting_node} passing #{traversed_nodes}" else return true end end return true if traverse_dependecies ( traversed_nodes , starting_node , node , edges , node_edges ( edges , node ) , escalation ) end false end
Recursive method for traversing dependencies and finding a cycle

 @param traversed_nodes [Array<InventoryRefresh::InventoryCollection> Already traversed nodes
 @param starting_node [InventoryRefresh::InventoryCollection] Node we've started the traversal on
 @param current_node [InventoryRefresh::InventoryCollection] Node we are currently on
 @param edges [Array<Array>] All graph edges
 @param dependencies [Array<InventoryRefresh::InventoryCollection> Dependencies of the current node
 @param escalation [Symbol] If :exception, this method throws exception when it finds a cycle
 @return [Boolean, Exception] Based on escalation returns true or raises exception if there is a cycle
Recursive method for traversing dependencies and finding a cycle