aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/callbacks.rb
diff options
context:
space:
mode:
authorJosé Valim <jose.valim@gmail.com>2012-01-04 21:29:05 +0100
committerJosé Valim <jose.valim@gmail.com>2012-01-04 21:29:05 +0100
commit0b24dc9148e4ec0487705dac666254301b30498a (patch)
treef9e90ae77edd4eff2fb5fc47874316d499f2f5f1 /activesupport/lib/active_support/callbacks.rb
parent49a1017235c4b73b4cdc718ee882f4cd9a7fb195 (diff)
downloadrails-0b24dc9148e4ec0487705dac666254301b30498a.tar.gz
rails-0b24dc9148e4ec0487705dac666254301b30498a.tar.bz2
rails-0b24dc9148e4ec0487705dac666254301b30498a.zip
Revert "AS::Callbacks: remove __define_runner"
Runners are used internally. This reverts commit 40c8aa706adbb60ff9d289016fb9020d48969fea.
Diffstat (limited to 'activesupport/lib/active_support/callbacks.rb')
-rw-r--r--activesupport/lib/active_support/callbacks.rb19
1 files changed, 16 insertions, 3 deletions
diff --git a/activesupport/lib/active_support/callbacks.rb b/activesupport/lib/active_support/callbacks.rb
index df3aeb6b8a..0495741c15 100644
--- a/activesupport/lib/active_support/callbacks.rb
+++ b/activesupport/lib/active_support/callbacks.rb
@@ -77,8 +77,8 @@ module ActiveSupport
# save
# end
#
- def run_callbacks(kind, key = nil, &block)
- self.class.__run_callbacks(key, kind, self, &block)
+ def run_callbacks(kind, *args, &block)
+ send("_run_#{kind}_callbacks", *args, &block)
end
private
@@ -376,12 +376,24 @@ module ActiveSupport
end
module ClassMethods
+ # Generate the internal runner method called by +run_callbacks+.
+ def __define_runner(symbol) #:nodoc:
+ runner_method = "_run_#{symbol}_callbacks"
+ unless private_method_defined?(runner_method)
+ class_eval <<-RUBY_EVAL, __FILE__, __LINE__ + 1
+ def #{runner_method}(key = nil, &blk)
+ self.class.__run_callback(key, :#{symbol}, self, &blk)
+ end
+ private :#{runner_method}
+ RUBY_EVAL
+ end
+ end
# This method calls the callback method for the given key.
# If this called first time it creates a new callback method for the key,
# calculating which callbacks can be omitted because of per_key conditions.
#
- def __run_callbacks(key, kind, object, &blk) #:nodoc:
+ def __run_callback(key, kind, object, &blk) #:nodoc:
name = __callback_runner_name(key, kind)
unless object.respond_to?(name)
str = send("_#{kind}_callbacks").compile(key, object)
@@ -606,6 +618,7 @@ module ActiveSupport
callbacks.each do |callback|
class_attribute "_#{callback}_callbacks"
send("_#{callback}_callbacks=", CallbackChain.new(callback, config))
+ __define_runner(callback)
end
end
end