diff options
author | Luke Kanies <luke@madstop.com> | 2009-11-01 13:16:39 -0600 |
---|---|---|
committer | test branch <puppet-dev@googlegroups.com> | 2010-02-17 06:50:53 -0800 |
commit | 329527f5173d17c9c2b788734033534009efcf04 (patch) | |
tree | 0164f85505d568c6585714b8fd69ee48aa487920 | |
parent | f8d7c44fea37dff3e9a86652699bffeab0fbe111 (diff) | |
download | puppet-329527f5173d17c9c2b788734033534009efcf04.tar.gz puppet-329527f5173d17c9c2b788734033534009efcf04.tar.xz puppet-329527f5173d17c9c2b788734033534009efcf04.zip |
Changing SimpleGraph.matching_edges to expect one event
It previously worked with multiple, but the only caller
actually only ever passed one event.
Signed-off-by: Luke Kanies <luke@madstop.com>
-rw-r--r-- | lib/puppet/simple_graph.rb | 26 | ||||
-rwxr-xr-x | spec/unit/simple_graph.rb | 11 |
2 files changed, 17 insertions, 20 deletions
diff --git a/lib/puppet/simple_graph.rb b/lib/puppet/simple_graph.rb index 5e8f5cdb7..91603945c 100644 --- a/lib/puppet/simple_graph.rb +++ b/lib/puppet/simple_graph.rb @@ -145,21 +145,19 @@ class Puppet::SimpleGraph # Collect all of the edges that the passed events match. Returns # an array of edges. - def matching_edges(events, base = nil) - events.collect do |event| - source = base || event.source + def matching_edges(event, base = nil) + source = base || event.resource - unless vertex?(source) - Puppet.warning "Got an event from invalid vertex %s" % source.ref - next - end - # Get all of the edges that this vertex should forward events - # to, which is the same thing as saying all edges directly below - # This vertex in the graph. - adjacent(source, :direction => :out, :type => :edges).find_all do |edge| - edge.match?(event.name) - end - end.compact.flatten + unless vertex?(source) + Puppet.warning "Got an event from invalid vertex #{source.ref}" + return [] + end + # Get all of the edges that this vertex should forward events + # to, which is the same thing as saying all edges directly below + # This vertex in the graph. + adjacent(source, :direction => :out, :type => :edges).find_all do |edge| + edge.match?(event.name) + end end # Return a reversed version of this graph. diff --git a/spec/unit/simple_graph.rb b/spec/unit/simple_graph.rb index 22d6ebe3d..f8596c7d6 100755 --- a/spec/unit/simple_graph.rb +++ b/spec/unit/simple_graph.rb @@ -34,7 +34,6 @@ describe Puppet::SimpleGraph do it "should always put its edges first when printing yaml" do @graph = Puppet::SimpleGraph.new @graph.add_edge(:one, :two) - p @graph.to_yaml_properties @graph.to_yaml_properties[0].should == "@edges" end @@ -349,8 +348,8 @@ describe Puppet::SimpleGraph do describe "when matching edges" do before do @graph = Puppet::SimpleGraph.new - @event = Puppet::Transaction::Event.new(:yay, "a") - @none = Puppet::Transaction::Event.new(:NONE, "a") + @event = Puppet::Transaction::Event.new(:name => :yay, :resource => "a") + @none = Puppet::Transaction::Event.new(:name => :NONE, :resource => "a") @edges = {} @edges["a/b"] = Puppet::Relationship.new("a", "b", {:event => :yay, :callback => :refresh}) @@ -359,16 +358,16 @@ describe Puppet::SimpleGraph do end it "should match edges whose source matches the source of the event" do - @graph.matching_edges([@event]).should == [@edges["a/b"]] + @graph.matching_edges(@event).should == [@edges["a/b"]] end it "should match always match nothing when the event is :NONE" do - @graph.matching_edges([@none]).should be_empty + @graph.matching_edges(@none).should be_empty end it "should match multiple edges" do @graph.add_edge(@edges["a/c"]) - edges = @graph.matching_edges([@event]) + edges = @graph.matching_edges(@event) edges.should be_include(@edges["a/b"]) edges.should be_include(@edges["a/c"]) end |