aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport
diff options
context:
space:
mode:
authorJosé Valim <jose.valim@gmail.com>2010-06-19 16:58:12 +0200
committerJosé Valim <jose.valim@gmail.com>2010-06-19 16:58:15 +0200
commita2b7fcb07ca47ca2285dee2afe97050532e94d07 (patch)
tree238b4e7c1e8a247495d34bc147a9cfb9e702996e /activesupport
parent8db8c6f4ce3e8dd7f90553ab7866bf9991773b98 (diff)
downloadrails-a2b7fcb07ca47ca2285dee2afe97050532e94d07.tar.gz
rails-a2b7fcb07ca47ca2285dee2afe97050532e94d07.tar.bz2
rails-a2b7fcb07ca47ca2285dee2afe97050532e94d07.zip
Change callbacks to automatically include DescendantsTracker and rename descendents to descendants.
Diffstat (limited to 'activesupport')
-rw-r--r--activesupport/lib/active_support/callbacks.rb10
-rw-r--r--activesupport/lib/active_support/core_ext/class/subclasses.rb10
-rw-r--r--activesupport/test/descendants_tracker_test.rb7
3 files changed, 17 insertions, 10 deletions
diff --git a/activesupport/lib/active_support/callbacks.rb b/activesupport/lib/active_support/callbacks.rb
index 3ff33eea72..c4e1eb2c04 100644
--- a/activesupport/lib/active_support/callbacks.rb
+++ b/activesupport/lib/active_support/callbacks.rb
@@ -1,6 +1,6 @@
+require 'active_support/descendants_tracker'
require 'active_support/core_ext/array/wrap'
require 'active_support/core_ext/class/inheritable_attributes'
-require 'active_support/core_ext/class/subclasses'
require 'active_support/core_ext/kernel/reporting'
require 'active_support/core_ext/kernel/singleton_class'
@@ -85,6 +85,10 @@ module ActiveSupport
module Callbacks
extend Concern
+ included do
+ extend ActiveSupport::DescendantsTracker
+ end
+
def run_callbacks(kind, *args, &block)
send("_run_#{kind}_callbacks", *args, &block)
end
@@ -428,7 +432,7 @@ module ActiveSupport
options = filters.last.is_a?(Hash) ? filters.pop : {}
filters.unshift(block) if block
- ([self] + self.descendents).each do |target|
+ ([self] + self.descendants).each do |target|
chain = target.send("_#{name}_callbacks")
yield chain, type, filters, options
target.__define_runner(name)
@@ -502,7 +506,7 @@ module ActiveSupport
def reset_callbacks(symbol)
callbacks = send("_#{symbol}_callbacks")
- self.descendents.each do |target|
+ self.descendants.each do |target|
chain = target.send("_#{symbol}_callbacks")
callbacks.each { |c| chain.delete(c) }
target.__define_runner(symbol)
diff --git a/activesupport/lib/active_support/core_ext/class/subclasses.rb b/activesupport/lib/active_support/core_ext/class/subclasses.rb
index bbd8f5aef6..7d58a8b56a 100644
--- a/activesupport/lib/active_support/core_ext/class/subclasses.rb
+++ b/activesupport/lib/active_support/core_ext/class/subclasses.rb
@@ -11,9 +11,9 @@ class Class #:nodoc:
# Rubinius
if defined?(Class.__subclasses__)
- def descendents
+ def descendants
subclasses = []
- __subclasses__.each {|k| subclasses << k; subclasses.concat k.descendents }
+ __subclasses__.each {|k| subclasses << k; subclasses.concat k.descendants }
subclasses
end
else
@@ -21,7 +21,7 @@ class Class #:nodoc:
begin
ObjectSpace.each_object(Class.new) {}
- def descendents
+ def descendants
subclasses = []
ObjectSpace.each_object(class << self; self; end) do |k|
subclasses << k unless k == self
@@ -30,7 +30,7 @@ class Class #:nodoc:
end
# JRuby
rescue StandardError
- def descendents
+ def descendants
subclasses = []
ObjectSpace.each_object(Class) do |k|
subclasses << k if k < self
@@ -48,7 +48,7 @@ class Class #:nodoc:
def self.subclasses_of(*superclasses) #:nodoc:
subclasses = []
superclasses.each do |klass|
- subclasses.concat klass.descendents.select {|k| k.anonymous? || k.reachable?}
+ subclasses.concat klass.descendants.select {|k| k.anonymous? || k.reachable?}
end
subclasses
end
diff --git a/activesupport/test/descendants_tracker_test.rb b/activesupport/test/descendants_tracker_test.rb
index 57c97b45d2..e3eccb8aa9 100644
--- a/activesupport/test/descendants_tracker_test.rb
+++ b/activesupport/test/descendants_tracker_test.rb
@@ -1,6 +1,7 @@
require 'abstract_unit'
require 'test/unit'
require 'active_support'
+require 'active_support/core_ext/hash/slice'
class DescendantsTrackerTest < Test::Unit::TestCase
class Parent
@@ -19,6 +20,8 @@ class DescendantsTrackerTest < Test::Unit::TestCase
class Grandchild2 < Child1
end
+ ALL = [Parent, Child1, Child2, Grandchild1, Grandchild2]
+
def test_descendants
assert_equal [Child1, Grandchild1, Grandchild2, Child2], Parent.descendants
assert_equal [Grandchild1, Grandchild2], Child1.descendants
@@ -32,9 +35,9 @@ class DescendantsTrackerTest < Test::Unit::TestCase
end
def test_clear_with_autoloaded_parent_children_and_granchildren
- mark_as_autoloaded Parent, Child1, Child2, Grandchild1, Grandchild2 do
+ mark_as_autoloaded *ALL do
ActiveSupport::DescendantsTracker.clear
- assert_equal Hash.new, ActiveSupport::DescendantsTracker.descendants
+ assert ActiveSupport::DescendantsTracker.descendants.slice(*ALL).empty?
end
end