Merge pull request #4417 from bogdan/remove_runner

AS::Callbacks: remove unused runner
This commit is contained in:
José Valim 2012-01-12 00:53:42 -08:00
commit e927f06b25
3 changed files with 5 additions and 18 deletions

@ -210,7 +210,7 @@ def initialize_dup(other)
@attributes = cloned_attributes
_run_initialize_callbacks if _initialize_callbacks.any?
run_callbacks(:initialize) if _initialize_callbacks.any?
@changed_attributes = {}
self.class.column_defaults.each do |attr, orig_value|

@ -76,8 +76,8 @@ module Callbacks
# save
# end
#
def run_callbacks(kind, *args, &block)
send("_run_#{kind}_callbacks", *args, &block)
def run_callbacks(kind, key = nil, &block)
self.class.__run_callbacks(key, kind, self, &block)
end
private
@ -379,24 +379,12 @@ def applicable_callbacks_for(key, object)
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_callback(key, kind, object, &blk) #:nodoc:
def __run_callbacks(key, kind, object, &blk) #:nodoc:
name = __callback_runner_name(key, kind)
unless object.respond_to?(name)
str = send("_#{kind}_callbacks").compile(key, object)
@ -621,7 +609,6 @@ def define_callbacks(*callbacks)
callbacks.each do |callback|
class_attribute "_#{callback}_callbacks"
send("_#{callback}_callbacks=", CallbackChain.new(callback, config))
__define_runner(callback)
end
end
end

@ -56,7 +56,7 @@ class Person
before_update :reset_me
def update
_run_update_callbacks do
run_callbacks(:update) do
# This will call when we are trying to call update on object.
end
end