Sha256: 009726417b1e7a29a69140f140ac4a44c026cebea4d69bf1da7cfe040938f59b

Contents?: true

Size: 877 Bytes

Versions: 21

Compression:

Stored size: 877 Bytes

Contents

#  Created by Luke Kanies on 2006-11-16.
#  Copyright (c) 2006. All rights reserved.

require 'puppet'
require 'puppet/simple_graph'

# A module that handles the small amount of graph stuff in Puppet.
module Puppet::Util::Graph
  # Make a graph where each of our children gets converted to
  # the receiving end of an edge.  Call the same thing on all
  # of our children, optionally using a block
  def to_graph(graph = nil, &block)
    # Allow our calling function to send in a graph, so that we
    # can call this recursively with one graph.
    graph ||= Puppet::SimpleGraph.new

    self.each do |child|
      unless block_given? and ! yield(child)
        graph.add_edge(self, child)

        child.to_graph(graph, &block) if child.respond_to?(:to_graph)
      end
    end

    # Do a topsort, which will throw an exception if the graph is cyclic.

    graph
  end
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
puppet-2.6.18 lib/puppet/util/graph.rb
puppet-2.6.17 lib/puppet/util/graph.rb
puppet-2.6.16 lib/puppet/util/graph.rb
puppet-2.6.15 lib/puppet/util/graph.rb
puppet-2.6.14 lib/puppet/util/graph.rb
puppet-2.6.13 lib/puppet/util/graph.rb
puppet-2.6.12 lib/puppet/util/graph.rb
puppet-2.6.11 lib/puppet/util/graph.rb
puppet-2.6.10 lib/puppet/util/graph.rb
puppet-2.7.3 lib/puppet/util/graph.rb
puppet-2.7.1 lib/puppet/util/graph.rb
puppet-2.6.9 lib/puppet/util/graph.rb
puppet-2.6.8 lib/puppet/util/graph.rb
puppet-2.6.7 lib/puppet/util/graph.rb
puppet-2.6.6 lib/puppet/util/graph.rb
puppet-2.6.5 lib/puppet/util/graph.rb
puppet-2.6.4 lib/puppet/util/graph.rb
puppet-2.6.3 lib/puppet/util/graph.rb
puppet-2.6.2 lib/puppet/util/graph.rb
puppet-2.6.1 lib/puppet/util/graph.rb