diff options
| author | Luke Kanies <luke@madstop.com> | 2008-07-04 15:35:18 -0500 |
|---|---|---|
| committer | Luke Kanies <luke@madstop.com> | 2008-07-04 15:35:18 -0500 |
| commit | 2863df288150da87a58ce4d938bbcf9a5d841f43 (patch) | |
| tree | 571c8de49b1133655551f6a43dd7f4ec39d28e30 | |
| parent | a37a7845073ef0b0923549364cbac5e0e39e3194 (diff) | |
| download | puppet-2863df288150da87a58ce4d938bbcf9a5d841f43.tar.gz puppet-2863df288150da87a58ce4d938bbcf9a5d841f43.tar.xz puppet-2863df288150da87a58ce4d938bbcf9a5d841f43.zip | |
Refactoring the Transaction::Event class.
The class had a 'transaction' accessor that was assigned
but never used, and it is simple enough that it needed
direct arguments rather than named arguments.
The rest of the code is changing the other classes that use
Events.
Signed-off-by: Luke Kanies <luke@madstop.com>
| -rw-r--r-- | lib/puppet/pgraph.rb | 2 | ||||
| -rw-r--r-- | lib/puppet/transaction.rb | 16 | ||||
| -rw-r--r-- | lib/puppet/transaction/change.rb | 6 | ||||
| -rw-r--r-- | lib/puppet/transaction/event.rb | 9 | ||||
| -rwxr-xr-x | spec/unit/other/pgraph.rb | 4 | ||||
| -rwxr-xr-x | spec/unit/transaction/change.rb | 2 | ||||
| -rwxr-xr-x | spec/unit/transaction/event.rb | 26 | ||||
| -rw-r--r-- | test/lib/puppettest/support/utils.rb | 2 | ||||
| -rwxr-xr-x | test/other/transactions.rb | 5 |
9 files changed, 23 insertions, 49 deletions
diff --git a/lib/puppet/pgraph.rb b/lib/puppet/pgraph.rb index 3bcc2ced0..55ad7d2c1 100644 --- a/lib/puppet/pgraph.rb +++ b/lib/puppet/pgraph.rb @@ -58,7 +58,7 @@ class Puppet::PGraph < Puppet::SimpleGraph # 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.event) + edge.match?(event.name) end end.compact.flatten end diff --git a/lib/puppet/transaction.rb b/lib/puppet/transaction.rb index 78704bb13..695d0434c 100644 --- a/lib/puppet/transaction.rb +++ b/lib/puppet/transaction.rb @@ -98,7 +98,7 @@ class Transaction # Create an edge with this resource as both the source and # target. The triggering method treats these specially for # logging. - events = resourceevents.collect { |e| e.event } + events = resourceevents.collect { |e| e.name } set_trigger(Puppet::Relationship.new(resource, resource, :callback => :refresh, :event => events)) end end @@ -280,7 +280,7 @@ class Transaction # of course, bad. edge = orig_edge.class.new(orig_edge.source, orig_edge.target) label = orig_edge.label.dup - label[:event] = events.collect { |e| e.event } + label[:event] = events.collect { |e| e.name } edge.label = label set_trigger(edge) end @@ -682,11 +682,7 @@ class Transaction [callback, subs.length] # And then add an event for it. - return [Puppet::Transaction::Event.new( - :event => :noop, - :transaction => self, - :source => resource - )] + return [Puppet::Transaction::Event.new(:noop, resource)] end if subs.length == 1 and subs[0].source == resource @@ -714,11 +710,7 @@ class Transaction end # And then add an event for it. - trigged << Puppet::Transaction::Event.new( - :event => :triggered, - :transaction => self, - :source => resource - ) + trigged << Puppet::Transaction::Event.new(:triggered, resource) triggered(resource, callback) end diff --git a/lib/puppet/transaction/change.rb b/lib/puppet/transaction/change.rb index e1863ee13..cc7629376 100644 --- a/lib/puppet/transaction/change.rb +++ b/lib/puppet/transaction/change.rb @@ -43,11 +43,7 @@ class Puppet::Transaction::Change name = @property.event(should) end - Puppet::Transaction::Event.new( - :event => name, - :transaction => transaction, - :source => self.resource - ) + Puppet::Transaction::Event.new(name, self.resource) end def initialize(property, currentvalue) diff --git a/lib/puppet/transaction/event.rb b/lib/puppet/transaction/event.rb index 418e70516..f1a48b382 100644 --- a/lib/puppet/transaction/event.rb +++ b/lib/puppet/transaction/event.rb @@ -9,14 +9,13 @@ class Puppet::Transaction::Event include Puppet::Util::MethodHelper include Puppet::Util::Errors - attr_accessor :event, :source, :transaction + attr_reader :name, :source - def initialize(args) - set_options symbolize_options(args) - requiredopts(:event, :source) + def initialize(name, source) + @name, @source = name, source end def to_s - @source.to_s + " -> " + self.event.to_s + source.to_s + " -> " + name.to_s end end diff --git a/spec/unit/other/pgraph.rb b/spec/unit/other/pgraph.rb index 25d99b921..cad0832a5 100755 --- a/spec/unit/other/pgraph.rb +++ b/spec/unit/other/pgraph.rb @@ -47,8 +47,8 @@ end describe Puppet::PGraph, " when matching edges" do before do @graph = Puppet::PGraph.new - @event = Puppet::Transaction::Event.new(:source => "a", :event => :yay) - @none = Puppet::Transaction::Event.new(:source => "a", :event => :NONE) + @event = Puppet::Transaction::Event.new(:yay, "a") + @none = Puppet::Transaction::Event.new(:NONE, "a") @edges = {} @edges["a/b"] = Puppet::Relationship.new("a", "b", {:event => :yay, :callback => :refresh}) diff --git a/spec/unit/transaction/change.rb b/spec/unit/transaction/change.rb index bb9915bda..6da87d85b 100755 --- a/spec/unit/transaction/change.rb +++ b/spec/unit/transaction/change.rb @@ -75,7 +75,7 @@ describe Puppet::Transaction::Change do @property.stubs(:warning) @property.expects(:event).with(@change.should).returns :myevent - Puppet::Transaction::Event.expects(:new).with { |args| args[:event] == :myevent } + Puppet::Transaction::Event.expects(:new).with { |name, source| name == :myevent } @change.event("a string") end diff --git a/spec/unit/transaction/event.rb b/spec/unit/transaction/event.rb index 7332b782d..9fd71aae1 100755 --- a/spec/unit/transaction/event.rb +++ b/spec/unit/transaction/event.rb @@ -7,31 +7,19 @@ require 'puppet/transaction/event' describe Puppet::Transaction::Event do Event = Puppet::Transaction::Event - it "should have an event accessor" do - event = Event.new :event => :foo, :source => "foo" - event.event.should == :foo + it "should require a name and a source" do + lambda { Event.new }.should raise_error(ArgumentError) end - it "should have a source accessor" do - event = Event.new :event => :foo, :source => "foo" - event.source.should == "foo" - end - - it "should have a transaction accessor" do - event = Event.new :event => :foo, :source => "foo" - event.transaction = "eh" - event.transaction.should == "eh" + it "should have a name getter" do + Event.new(:foo, "bar").name.should == :foo end - it "should require a source" do - lambda { Event.new :event => :foo }.should raise_error - end - - it "should require an event" do - lambda { Event.new :source => "eh" }.should raise_error + it "should have a source accessor" do + Event.new(:foo, "bar").source.should == "bar" end it "should be able to produce a string containing the event name and the source" do - Event.new(:event => :event, :source => :source).to_s.should == "source -> event" + Event.new(:event, :source).to_s.should == "source -> event" end end diff --git a/test/lib/puppettest/support/utils.rb b/test/lib/puppettest/support/utils.rb index cb4a6924c..654531cfc 100644 --- a/test/lib/puppettest/support/utils.rb +++ b/test/lib/puppettest/support/utils.rb @@ -88,7 +88,7 @@ module PuppetTest::Support::Utils newevents = nil assert_nothing_raised("Transaction %s %s failed" % [type, msg]) { newevents = trans.send(method).reject { |e| e.nil? }.collect { |e| - e.event + e.name } } diff --git a/test/other/transactions.rb b/test/other/transactions.rb index ff266b8d9..7f42bb6f4 100755 --- a/test/other/transactions.rb +++ b/test/other/transactions.rb @@ -815,7 +815,7 @@ class TestTransactions < Test::Unit::TestCase assert(changes.length > 0, "did not get any changes") changes.each do |change| - assert_equal(resource, change.source, "change did not get proxy set correctly") + assert_equal(resource, change.resource, "change did not get proxy set correctly") end end @@ -906,9 +906,8 @@ class TestTransactions < Test::Unit::TestCase assert_instance_of(Array, result) event = result.shift assert_instance_of(Puppet::Transaction::Event, event) - assert_equal(:triggered, event.event, "event was not set correctly") + assert_equal(:triggered, event.name, "event was not set correctly") assert_equal(c, event.source, "source was not set correctly") - assert_equal(trans, event.transaction, "transaction was not set correctly") assert(trans.triggered?(c, :refresh), "Transaction did not store the trigger") |
