This module provides an internal implementation to track descendants which is faster than iterating through ObjectSpace.
Methods
- descendants
- descendants
- direct_descendants
- direct_descendants
- inherited
- store_inherited
- subclasses
- subclasses
Class Public methods
descendants(klass)
📝 Source code
# File activesupport/lib/active_support/descendants_tracker.rb, line 62
def descendants(klass)
klass.descendants
end
🔎 See on GitHub
direct_descendants(klass)
📝 Source code
# File activesupport/lib/active_support/descendants_tracker.rb, line 11
def direct_descendants(klass)
ActiveSupport::Deprecation.warn(<<~MSG)
ActiveSupport::DescendantsTracker.direct_descendants is deprecated and will be removed in Rails 7.1.
Use ActiveSupport::DescendantsTracker.subclasses instead.
MSG
subclasses(klass)
end
🔎 See on GitHub
store_inherited(klass, descendant)
This is the only method that is not thread safe, but is only ever called during the eager loading phase.
📝 Source code
# File activesupport/lib/active_support/descendants_tracker.rb, line 138
def store_inherited(klass, descendant)
(@@direct_descendants[klass] ||= DescendantsArray.new) << descendant
end
🔎 See on GitHub
subclasses(klass)
📝 Source code
# File activesupport/lib/active_support/descendants_tracker.rb, line 58
def subclasses(klass)
klass.subclasses
end
🔎 See on GitHub
Instance Public methods
descendants()
📝 Source code
# File activesupport/lib/active_support/descendants_tracker.rb, line 88
def descendants
subclasses.concat(subclasses.flat_map(&:descendants))
end
🔎 See on GitHub
direct_descendants()
📝 Source code
# File activesupport/lib/active_support/descendants_tracker.rb, line 92
def direct_descendants
ActiveSupport::Deprecation.warn(<<~MSG)
ActiveSupport::DescendantsTracker#direct_descendants is deprecated and will be removed in Rails 7.1.
Use #subclasses instead.
MSG
subclasses
end
🔎 See on GitHub
inherited(base)
📝 Source code
# File activesupport/lib/active_support/descendants_tracker.rb, line 153
def inherited(base)
DescendantsTracker.store_inherited(self, base)
super
end
🔎 See on GitHub
subclasses()
📝 Source code
# File activesupport/lib/active_support/descendants_tracker.rb, line 82
def subclasses
subclasses = super
subclasses.reject! { |d| @@excluded_descendants[d] }
subclasses
end
🔎 See on GitHub