Skip to content

Commit f28fc93

Browse files
committed
Revert "AS::Callbacks: remove __define_runner"
Runners are used internally. This reverts commit 40c8aa7.
1 parent 91c1f01 commit f28fc93

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

activesupport/lib/active_support/callbacks.rb

+16-3
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@ module Callbacks
7777
# save
7878
# end
7979
#
80-
def run_callbacks(kind, key = nil, &block)
81-
self.class.__run_callbacks(key, kind, self, &block)
80+
def run_callbacks(kind, *args, &block)
81+
send("_run_#{kind}_callbacks", *args, &block)
8282
end
8383

8484
private
@@ -376,12 +376,24 @@ def compile(key=nil, object=nil)
376376
end
377377

378378
module ClassMethods
379+
# Generate the internal runner method called by +run_callbacks+.
380+
def __define_runner(symbol) #:nodoc:
381+
runner_method = "_run_#{symbol}_callbacks"
382+
unless private_method_defined?(runner_method)
383+
class_eval <<-RUBY_EVAL, __FILE__, __LINE__ + 1
384+
def #{runner_method}(key = nil, &blk)
385+
self.class.__run_callback(key, :#{symbol}, self, &blk)
386+
end
387+
private :#{runner_method}
388+
RUBY_EVAL
389+
end
390+
end
379391

380392
# This method calls the callback method for the given key.
381393
# If this called first time it creates a new callback method for the key,
382394
# calculating which callbacks can be omitted because of per_key conditions.
383395
#
384-
def __run_callbacks(key, kind, object, &blk) #:nodoc:
396+
def __run_callback(key, kind, object, &blk) #:nodoc:
385397
name = __callback_runner_name(key, kind)
386398
unless object.respond_to?(name)
387399
str = send("_#{kind}_callbacks").compile(key, object)
@@ -606,6 +618,7 @@ def define_callbacks(*callbacks)
606618
callbacks.each do |callback|
607619
class_attribute "_#{callback}_callbacks"
608620
send("_#{callback}_callbacks=", CallbackChain.new(callback, config))
621+
__define_runner(callback)
609622
end
610623
end
611624
end

0 commit comments

Comments
 (0)