diff options
author | Josh Peek <josh@joshpeek.com> | 2008-04-04 20:26:42 +0000 |
---|---|---|
committer | Josh Peek <josh@joshpeek.com> | 2008-04-04 20:26:42 +0000 |
commit | 08318b8bcd32bae741e672899a33c6a7d52664c8 (patch) | |
tree | 5f7b491567621560d1c618e93fb8ab15155a3dbf /activesupport | |
parent | 36b8073ff553e8939d78ca2371ffdec7eb8f8071 (diff) | |
download | rails-08318b8bcd32bae741e672899a33c6a7d52664c8.tar.gz rails-08318b8bcd32bae741e672899a33c6a7d52664c8.tar.bz2 rails-08318b8bcd32bae741e672899a33c6a7d52664c8.zip |
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
Diffstat (limited to 'activesupport')
-rw-r--r-- | activesupport/CHANGELOG | 2 | ||||
-rw-r--r-- | activesupport/lib/active_support/callbacks.rb | 28 |
2 files changed, 13 insertions, 17 deletions
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 |