From 08318b8bcd32bae741e672899a33c6a7d52664c8 Mon Sep 17 00:00:00 2001 From: Josh Peek Date: Fri, 4 Apr 2008 20:26:42 +0000 Subject: Replaced callback method evaluation in AssociationCollection class to use ActiveSupport::Callbacks. Modified ActiveSupport::Callbacks::Callback#call to accept multiple arguments. git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@9225 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- activesupport/CHANGELOG | 2 ++ activesupport/lib/active_support/callbacks.rb | 28 +++++++++++---------------- 2 files changed, 13 insertions(+), 17 deletions(-) (limited to 'activesupport') diff --git a/activesupport/CHANGELOG b/activesupport/CHANGELOG index b2955ab69d..79522a0f0e 100644 --- a/activesupport/CHANGELOG +++ b/activesupport/CHANGELOG @@ -1,5 +1,7 @@ *SVN* +* Modified ActiveSupport::Callbacks::Callback#call to accept multiple arguments. + * Time #yesterday and #tomorrow behave correctly crossing DST boundary. Closes #7399 [sblackstone] * TimeWithZone: Adding tests for dst and leap day edge cases when advancing time [Geoff Buesing] diff --git a/activesupport/lib/active_support/callbacks.rb b/activesupport/lib/active_support/callbacks.rb index 40d71af69d..329cc2fdc7 100644 --- a/activesupport/lib/active_support/callbacks.rb +++ b/activesupport/lib/active_support/callbacks.rb @@ -149,8 +149,8 @@ module ActiveSupport self.class.new(@kind, @method, @options.dup) end - def call(object, &block) - evaluate_method(method, object, &block) if should_run_callback?(object) + def call(*args, &block) + evaluate_method(method, *args, &block) if should_run_callback?(*args) rescue LocalJumpError raise ArgumentError, "Cannot yield from a Proc type filter. The Proc must take two " + @@ -158,24 +158,18 @@ module ActiveSupport end private - def evaluate_method(method, object, &block) + def evaluate_method(method, *args, &block) case method when Symbol - object.send(method, &block) + object = args.shift + object.send(method, *args, &block) when String - eval(method, object.instance_eval { binding }) + eval(method, args.first.instance_eval { binding }) when Proc, Method - case method.arity - when -1, 1 - method.call(object, &block) - when 2 - method.call(object, block) - else - raise ArgumentError, 'Callback blocks must take one or two arguments.' - end + method.call(*args, &block) else if method.respond_to?(kind) - method.send(kind, object, &block) + method.send(kind, *args, &block) else raise ArgumentError, "Callbacks must be a symbol denoting the method to call, a string to be evaluated, " + @@ -184,11 +178,11 @@ module ActiveSupport end end - def should_run_callback?(object) + def should_run_callback?(*args) if options[:if] - evaluate_method(options[:if], object) + evaluate_method(options[:if], *args) elsif options[:unless] - !evaluate_method(options[:unless], object) + !evaluate_method(options[:unless], *args) else true end -- cgit v1.2.3