aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/callbacks.rb
diff options
context:
space:
mode:
authorRafael Mendonça França <rafaelmfranca@gmail.com>2012-06-01 12:18:11 -0300
committerRafael Mendonça França <rafaelmfranca@gmail.com>2012-06-01 15:14:06 -0300
commita769fe9db16a792164363b49e4c7f07f6e412eaa (patch)
tree6a39de2df7742e9e75db396347ea838633337989 /activesupport/lib/active_support/callbacks.rb
parent60b4290f1b978d2220c913b99a6162e8f324f833 (diff)
downloadrails-a769fe9db16a792164363b49e4c7f07f6e412eaa.tar.gz
rails-a769fe9db16a792164363b49e4c7f07f6e412eaa.tar.bz2
rails-a769fe9db16a792164363b49e4c7f07f6e412eaa.zip
Revert some ActiveSupport::Callbacks changes.
This reverts commits 911a0859ac065aa8e8834ac985353d659c7c7b65 and 30b31f51af6f7094c4a27b086755fc66c368d6fa. Reason: these changes make the Active Model tests fail randomly. Some examples: http://travis-ci.org/#!/rails/rails/jobs/1498992 http://travis-ci.org/#!/rails/rails/jobs/1496948 http://travis-ci.org/#!/rails/rails/jobs/1489985 This script was used to reproduce these breaks: https://gist.github.com/f6828a03ee4d40bffbc3 200 times, 0 failures
Diffstat (limited to 'activesupport/lib/active_support/callbacks.rb')
-rw-r--r--activesupport/lib/active_support/callbacks.rb19
1 files changed, 16 insertions, 3 deletions
diff --git a/activesupport/lib/active_support/callbacks.rb b/activesupport/lib/active_support/callbacks.rb
index a9253c186d..0aa3efbb63 100644
--- a/activesupport/lib/active_support/callbacks.rb
+++ b/activesupport/lib/active_support/callbacks.rb
@@ -328,17 +328,26 @@ module ActiveSupport
# if it was not yet defined.
# This generated method plays caching role.
def __define_callbacks(kind, object) #:nodoc:
- chain = object.send("_#{kind}_callbacks")
- name = "_run_callbacks_#{chain.object_id.abs}"
+ name = __callback_runner_name(kind)
unless object.respond_to?(name, true)
+ str = object.send("_#{kind}_callbacks").compile
class_eval <<-RUBY_EVAL, __FILE__, __LINE__ + 1
- def #{name}() #{chain.compile} end
+ def #{name}() #{str} end
protected :#{name}
RUBY_EVAL
end
name
end
+ def __reset_runner(symbol)
+ name = __callback_runner_name(symbol)
+ undef_method(name) if method_defined?(name)
+ end
+
+ def __callback_runner_name(kind)
+ "_run__#{self.name.hash.abs}__#{kind}__callbacks"
+ end
+
# This is used internally to append, prepend and skip callbacks to the
# CallbackChain.
#
@@ -350,6 +359,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.__reset_runner(name)
end
end
@@ -437,9 +447,12 @@ module ActiveSupport
chain = target.send("_#{symbol}_callbacks").dup
callbacks.each { |c| chain.delete(c) }
target.send("_#{symbol}_callbacks=", chain)
+ target.__reset_runner(symbol)
end
self.send("_#{symbol}_callbacks=", callbacks.dup.clear)
+
+ __reset_runner(symbol)
end
# Define sets of events in the object lifecycle that support callbacks.