~ubuntu-branches/ubuntu/oneiric/puppet/oneiric-security

« back to all changes in this revision

Viewing changes to lib/puppet/util/graph.rb

  • Committer: Bazaar Package Importer
  • Author(s): Micah Anderson
  • Date: 2008-07-26 15:43:45 UTC
  • mto: (3.1.1 lenny) (1.3.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 16.
  • Revision ID: james.westby@ubuntu.com-20080726154345-1fmgo76b4l72ulvc
ImportĀ upstreamĀ versionĀ 0.24.5

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#  Created by Luke Kanies on 2006-11-16.
 
2
#  Copyright (c) 2006. All rights reserved.
 
3
 
 
4
require 'puppet'
 
5
require 'puppet/pgraph'
 
6
 
 
7
# A module that handles the small amount of graph stuff in Puppet.
 
8
module Puppet::Util::Graph
 
9
    # Make a graph where each of our children gets converted to
 
10
    # the receiving end of an edge.  Call the same thing on all
 
11
    # of our children, optionally using a block
 
12
    def to_graph(graph = nil, &block)
 
13
        # Allow our calling function to send in a graph, so that we
 
14
        # can call this recursively with one graph.
 
15
        graph ||= Puppet::PGraph.new
 
16
        
 
17
        self.each do |child|
 
18
            unless block_given? and ! yield(child)
 
19
                graph.add_edge(self, child)
 
20
                
 
21
                if child.respond_to?(:to_graph)
 
22
                    child.to_graph(graph, &block)
 
23
                end
 
24
            end
 
25
        end
 
26
 
 
27
        # Do a topsort, which will throw an exception if the graph is cyclic.
 
28
        
 
29
        graph
 
30
    end
 
31
end
 
32