aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/callbacks.rb
diff options
context:
space:
mode:
authorRyan Wallace <rywall@gmail.com>2018-02-06 14:53:26 -0500
committerRyan Wallace <rywall@gmail.com>2018-02-06 16:05:39 -0500
commit56640b4de4e3245b087ca16e0f3bec751c6d6fb7 (patch)
treeaeeca67774cfc9068de83ee8f1b3265f7629995c /activesupport/lib/active_support/callbacks.rb
parentd57c52a385eb57c6ce8c6d124ab5e186f931d142 (diff)
downloadrails-56640b4de4e3245b087ca16e0f3bec751c6d6fb7.tar.gz
rails-56640b4de4e3245b087ca16e0f3bec751c6d6fb7.tar.bz2
rails-56640b4de4e3245b087ca16e0f3bec751c6d6fb7.zip
Define callbacks on descendants.
We set callbacks on all descendants, so we need to make sure that they are also defined on all descendants as well.
Diffstat (limited to 'activesupport/lib/active_support/callbacks.rb')
-rw-r--r--activesupport/lib/active_support/callbacks.rb36
1 files changed, 19 insertions, 17 deletions
diff --git a/activesupport/lib/active_support/callbacks.rb b/activesupport/lib/active_support/callbacks.rb
index 0ed4681b7d..cece3eb19f 100644
--- a/activesupport/lib/active_support/callbacks.rb
+++ b/activesupport/lib/active_support/callbacks.rb
@@ -806,28 +806,30 @@ module ActiveSupport
def define_callbacks(*names)
options = names.extract_options!
- names.each do |name|
- name = name.to_sym
+ ([self] + ActiveSupport::DescendantsTracker.descendants(self)).each do |target|
+ names.each do |name|
+ name = name.to_sym
- set_callbacks name, CallbackChain.new(name, options)
+ target.set_callbacks name, CallbackChain.new(name, options)
- module_eval <<-RUBY, __FILE__, __LINE__ + 1
- def _run_#{name}_callbacks(&block)
- run_callbacks #{name.inspect}, &block
- end
+ target.module_eval <<-RUBY, __FILE__, __LINE__ + 1
+ def _run_#{name}_callbacks(&block)
+ run_callbacks #{name.inspect}, &block
+ end
- def self._#{name}_callbacks
- get_callbacks(#{name.inspect})
- end
+ def self._#{name}_callbacks
+ get_callbacks(#{name.inspect})
+ end
- def self._#{name}_callbacks=(value)
- set_callbacks(#{name.inspect}, value)
- end
+ def self._#{name}_callbacks=(value)
+ set_callbacks(#{name.inspect}, value)
+ end
- def _#{name}_callbacks
- __callbacks[#{name.inspect}]
- end
- RUBY
+ def _#{name}_callbacks
+ __callbacks[#{name.inspect}]
+ end
+ RUBY
+ end
end
end