diff options
author | Luke Kanies <luke@madstop.com> | 2009-03-10 04:07:12 -0500 |
---|---|---|
committer | Luke Kanies <luke@madstop.com> | 2009-03-10 04:07:12 -0500 |
commit | f8dea989e3f5bd7d3d823a6c3dc3cf76cd5cba4e (patch) | |
tree | 29bbe8128203444ed2e47207c69d87601fb30c21 /lib | |
parent | d0fc2f5738a78c51128f6377c03fe42cf50371a0 (diff) | |
download | puppet-f8dea989e3f5bd7d3d823a6c3dc3cf76cd5cba4e.tar.gz puppet-f8dea989e3f5bd7d3d823a6c3dc3cf76cd5cba4e.tar.xz puppet-f8dea989e3f5bd7d3d823a6c3dc3cf76cd5cba4e.zip |
Fixing #1949 - relationships now use attributes instead of a label
This was important because the use of the label to store attributes
was a holdover from the GRATR library, and if we didn't cease its
use before we switched to RESTful catalogs, then we'd be stuck with
the @label instance variable forever, essentially.
Now we can add and remove variables however we please.
Signed-off-by: Luke Kanies <luke@madstop.com>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/puppet/relationship.rb | 49 | ||||
-rw-r--r-- | lib/puppet/transaction.rb | 6 |
2 files changed, 23 insertions, 32 deletions
diff --git a/lib/puppet/relationship.rb b/lib/puppet/relationship.rb index 05b7dc39e..984dffeeb 100644 --- a/lib/puppet/relationship.rb +++ b/lib/puppet/relationship.rb @@ -10,40 +10,26 @@ # It used to be a subclass of GRATR::Edge, but that class has weird hash # overrides that dramatically slow down the graphing. class Puppet::Relationship - attr_accessor :source, :target, :label + attr_accessor :source, :target, :callback - # Return the callback - def callback - if label - label[:callback] - else - nil - end - end + attr_reader :event - # Return our event. - def event - if label - label[:event] - else - nil + def event=(event) + if event != :NONE and ! callback + raise ArgumentError, "You must pass a callback for non-NONE events" end + @event = event end - - def initialize(source, target, label = {}) - if label - unless label.is_a?(Hash) - raise ArgumentError, "Relationship labels must be a hash" - end - - if label[:event] and label[:event] != :NONE and ! label[:callback] - raise ArgumentError, "You must pass a callback for non-NONE events" + + def initialize(source, target, options = {}) + @source, @target = source, target + + options ||= {} + [:callback, :event].each do |option| + if value = options[option] + send(option.to_s + "=", value) end - else - label = {} end - - @source, @target, @label = source, target, label end # Does the passed event match our event? This is where the meaning @@ -57,6 +43,13 @@ class Puppet::Relationship return false end end + + def label + result = {} + result[:callback] = callback if callback + result[:event] = event if event + result + end def ref "%s => %s" % [source, target] diff --git a/lib/puppet/transaction.rb b/lib/puppet/transaction.rb index cb17de7b9..884206b4c 100644 --- a/lib/puppet/transaction.rb +++ b/lib/puppet/transaction.rb @@ -253,10 +253,8 @@ class Transaction # We have to dup the label here, else we modify the original edge label, # which affects whether a given event will match on the next run, which is, # 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.name } - edge.label = label + edge = orig_edge.class.new(orig_edge.source, orig_edge.target, orig_edge.label) + edge.event = events.collect { |e| e.name } set_trigger(edge) end |