aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport
diff options
context:
space:
mode:
authorBogdan Gusiev <agresso@gmail.com>2011-12-28 18:03:18 +0200
committerSergey Nartimov <just.lest@gmail.com>2012-01-03 22:14:37 +0300
commit5b8d27000b23e7561ef09d3ca3e50ac50bb5885b (patch)
treefbdec86a21847b2e097b58b1c45de088f51beeef /activesupport
parent4e8286fe124dd5a54960fce191b86fa00010cd3b (diff)
downloadrails-5b8d27000b23e7561ef09d3ca3e50ac50bb5885b.tar.gz
rails-5b8d27000b23e7561ef09d3ca3e50ac50bb5885b.tar.bz2
rails-5b8d27000b23e7561ef09d3ca3e50ac50bb5885b.zip
Refactor AS::Callbacks
Extracted `__reset_runner` from `__define_runner` And call it in proper places
Diffstat (limited to 'activesupport')
-rw-r--r--activesupport/lib/active_support/callbacks.rb14
1 files changed, 8 insertions, 6 deletions
diff --git a/activesupport/lib/active_support/callbacks.rb b/activesupport/lib/active_support/callbacks.rb
index 2ebafa28dd..0495741c15 100644
--- a/activesupport/lib/active_support/callbacks.rb
+++ b/activesupport/lib/active_support/callbacks.rb
@@ -378,9 +378,6 @@ module ActiveSupport
module ClassMethods
# Generate the internal runner method called by +run_callbacks+.
def __define_runner(symbol) #:nodoc:
- name = __callback_runner_name(nil, symbol)
- undef_method(name) if method_defined?(name)
-
runner_method = "_run_#{symbol}_callbacks"
unless private_method_defined?(runner_method)
class_eval <<-RUBY_EVAL, __FILE__, __LINE__ + 1
@@ -408,6 +405,11 @@ module ActiveSupport
object.send(name, &blk)
end
+ def __reset_runner(symbol)
+ name = __callback_runner_name(nil, symbol)
+ undef_method(name) if method_defined?(name)
+ end
+
def __callback_runner_name(key, kind)
"_run__#{self.name.hash.abs}__#{kind}__#{key.hash.abs}__callbacks"
end
@@ -423,7 +425,7 @@ module ActiveSupport
([self] + ActiveSupport::DescendantsTracker.descendants(self)).reverse.each do |target|
chain = target.send("_#{name}_callbacks")
yield target, chain.dup, type, filters, options
- target.__define_runner(name)
+ target.__reset_runner(name)
end
end
@@ -537,12 +539,12 @@ module ActiveSupport
chain = target.send("_#{symbol}_callbacks").dup
callbacks.each { |c| chain.delete(c) }
target.send("_#{symbol}_callbacks=", chain)
- target.__define_runner(symbol)
+ target.__reset_runner(symbol)
end
self.send("_#{symbol}_callbacks=", callbacks.dup.clear)
- __define_runner(symbol)
+ __reset_runner(symbol)
end
# Define sets of events in the object lifecycle that support callbacks.