diff options
author | José Valim <jose.valim@gmail.com> | 2012-01-12 00:53:42 -0800 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2012-01-12 00:53:42 -0800 |
commit | e927f06b2528bef52087dd12f012c20ab26fb59c (patch) | |
tree | bbfb4130c9e3514d92a382f6fa836d37633c8420 | |
parent | 838d30f182b1fa0cabd977e98fc47b4adb2064e4 (diff) | |
parent | 19357a7b023fd56a5b381cd8894bb520c60cdb59 (diff) | |
download | rails-e927f06b2528bef52087dd12f012c20ab26fb59c.tar.gz rails-e927f06b2528bef52087dd12f012c20ab26fb59c.tar.bz2 rails-e927f06b2528bef52087dd12f012c20ab26fb59c.zip |
Merge pull request #4417 from bogdan/remove_runner
AS::Callbacks: remove unused runner
-rw-r--r-- | activerecord/lib/active_record/core.rb | 2 | ||||
-rw-r--r-- | activesupport/lib/active_support/callbacks.rb | 19 | ||||
-rw-r--r-- | railties/guides/source/active_model_basics.textile | 2 |
3 files changed, 5 insertions, 18 deletions
diff --git a/activerecord/lib/active_record/core.rb b/activerecord/lib/active_record/core.rb index 89f6eccbd2..22574c4ce7 100644 --- a/activerecord/lib/active_record/core.rb +++ b/activerecord/lib/active_record/core.rb @@ -210,7 +210,7 @@ module ActiveRecord @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| diff --git a/activesupport/lib/active_support/callbacks.rb b/activesupport/lib/active_support/callbacks.rb index f1d00aab6d..c20de7cd78 100644 --- a/activesupport/lib/active_support/callbacks.rb +++ b/activesupport/lib/active_support/callbacks.rb @@ -76,8 +76,8 @@ module ActiveSupport # 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 @@ 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_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 @@ module ActiveSupport callbacks.each do |callback| class_attribute "_#{callback}_callbacks" send("_#{callback}_callbacks=", CallbackChain.new(callback, config)) - __define_runner(callback) end end end diff --git a/railties/guides/source/active_model_basics.textile b/railties/guides/source/active_model_basics.textile index 9c8ad24cee..98b3533000 100644 --- a/railties/guides/source/active_model_basics.textile +++ b/railties/guides/source/active_model_basics.textile @@ -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 |