aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/descendants_tracker.rb
diff options
context:
space:
mode:
Diffstat (limited to 'activesupport/lib/active_support/descendants_tracker.rb')
-rw-r--r--activesupport/lib/active_support/descendants_tracker.rb24
1 files changed, 14 insertions, 10 deletions
diff --git a/activesupport/lib/active_support/descendants_tracker.rb b/activesupport/lib/active_support/descendants_tracker.rb
index a587d7770c..6cba84d79e 100644
--- a/activesupport/lib/active_support/descendants_tracker.rb
+++ b/activesupport/lib/active_support/descendants_tracker.rb
@@ -4,16 +4,23 @@ module ActiveSupport
# This module provides an internal implementation to track descendants
# which is faster than iterating through ObjectSpace.
module DescendantsTracker
- @@descendants = Hash.new { |h, k| h[k] = [] }
+ @@direct_descendants = Hash.new { |h, k| h[k] = [] }
- def self.descendants
- @@descendants
+ def self.direct_descendants(klass)
+ @@direct_descendants[klass]
+ end
+
+ def self.descendants(klass)
+ @@direct_descendants[klass].inject([]) do |descendants, klass|
+ descendants << klass
+ descendants.concat klass.descendants
+ end
end
def self.clear
- @@descendants.each do |klass, descendants|
+ @@direct_descendants.each do |klass, descendants|
if ActiveSupport::Dependencies.autoloaded?(klass)
- @@descendants.delete(klass)
+ @@direct_descendants.delete(klass)
else
descendants.reject! { |v| ActiveSupport::Dependencies.autoloaded?(v) }
end
@@ -26,14 +33,11 @@ module ActiveSupport
end
def direct_descendants
- @@descendants[self]
+ DescendantsTracker.direct_descendants(self)
end
def descendants
- @@descendants[self].inject([]) do |descendants, klass|
- descendants << klass
- descendants.concat klass.descendants
- end
+ DescendantsTracker.descendants(self)
end
end
end \ No newline at end of file