summaryrefslogtreecommitdiff
path: root/lib/chef/event_dispatch
diff options
context:
space:
mode:
authorNoah Kantrowitz <noah@coderanger.net>2015-07-31 14:45:34 -0700
committerNoah Kantrowitz <noah@coderanger.net>2015-07-31 14:45:34 -0700
commit63711b9da81c9db8466a2c45670f8d94cfdaac68 (patch)
tree64e5eb035cda1084848e285de3d49e83107821a1 /lib/chef/event_dispatch
parent85d3dfb6a361c774b6a1e4d4e437b836d5dd19cc (diff)
downloadchef-63711b9da81c9db8466a2c45670f8d94cfdaac68.tar.gz
Support forwards compatibility for event sinks.
We can add new arguments and events without breaking compat as long as the new arguments are added at the end. The new args will be silently trimmed for sending to older event sinks, and new event types will be ignored.
Diffstat (limited to 'lib/chef/event_dispatch')
-rw-r--r--lib/chef/event_dispatch/dispatcher.rb12
1 files changed, 11 insertions, 1 deletions
diff --git a/lib/chef/event_dispatch/dispatcher.rb b/lib/chef/event_dispatch/dispatcher.rb
index 370f8c51b4..9e17d78507 100644
--- a/lib/chef/event_dispatch/dispatcher.rb
+++ b/lib/chef/event_dispatch/dispatcher.rb
@@ -28,7 +28,17 @@ class Chef
# Define a method that will be forwarded to all
def self.def_forwarding_method(method_name)
define_method(method_name) do |*args|
- @subscribers.each { |s| s.send(method_name, *args) }
+ @subscribers.each do |s|
+ # Skip new/unsupported event names.
+ if s.respond_to?(method_name)
+ mth = s.method(method_name)
+ # Anything with a *args is arity -1, so use all arguments.
+ arity = mth.arity < 0 ? args.length : mth.arity
+ # Trim arguments to match what the subscriber expects to allow
+ # adding new arguments without breaking compat.
+ mth.call(*args.take(arity))
+ end
+ end
end
end