@@ -77,8 +77,8 @@ module Callbacks
77
77
# save
78
78
# end
79
79
#
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 )
82
82
end
83
83
84
84
private
@@ -376,12 +376,24 @@ def compile(key=nil, object=nil)
376
376
end
377
377
378
378
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
379
391
380
392
# This method calls the callback method for the given key.
381
393
# If this called first time it creates a new callback method for the key,
382
394
# calculating which callbacks can be omitted because of per_key conditions.
383
395
#
384
- def __run_callbacks ( key , kind , object , &blk ) #:nodoc:
396
+ def __run_callback ( key , kind , object , &blk ) #:nodoc:
385
397
name = __callback_runner_name ( key , kind )
386
398
unless object . respond_to? ( name )
387
399
str = send ( "_#{ kind } _callbacks" ) . compile ( key , object )
@@ -606,6 +618,7 @@ def define_callbacks(*callbacks)
606
618
callbacks . each do |callback |
607
619
class_attribute "_#{ callback } _callbacks"
608
620
send ( "_#{ callback } _callbacks=" , CallbackChain . new ( callback , config ) )
621
+ __define_runner ( callback )
609
622
end
610
623
end
611
624
end
0 commit comments