Module: ActiveSupport::DescendantsTracker
Relationships & Source Files | |
Namespace Children | |
Modules:
| |
Classes:
| |
Extension / Inclusion / Inheritance Descendants | |
Extended In:
::AbstractController::Base ,
::ActionCable::Engine ,
::ActionController::API ,
::ActionController::Base ,
::ActionController::Metal ,
::ActionController::Railtie ,
::ActionDispatch::Railtie ,
::ActionMailbox::Engine ,
::ActionMailer::Base ,
::ActionMailer::Preview ,
::ActionMailer::Railtie ,
::ActionText::Engine ,
::ActionView::Railtie ,
::ActionView::TestCase::TestController ,
::ActiveJob::Railtie ,
::ActiveModel::Railtie ,
::ActiveRecord::Base ,
::ActiveRecord::Railtie ,
::ActiveStorage::Engine ,
Railtie ,
::I18n::Railtie ,
::Rails::Application ,
::Rails::ApplicationController ,
::Rails::Engine ,
::Rails::HealthController ,
::Rails::InfoController ,
::Rails::MailersController ,
::Rails::PwaController ,
::Rails::Railtie ,
::Rails::TestUnitRailtie ,
::Rails::WelcomeController
| |
Defined in: | activesupport/lib/active_support/descendants_tracker.rb |
Overview
This module provides an internal implementation to track descendants which is faster than iterating through ObjectSpace
.
However Ruby 3.1 provide a fast native Class#subclasses
method, so if you know your code won’t be executed on older rubies, including DescendantsTracker
does not provide any benefit.
Class Method Summary
- .descendants(klass)
- .subclasses(klass)
- .clear(classes) Internal use only
- .disable_clear! Internal use only
- .reject!(classes) Internal use only
Instance Method Summary
Class Method Details
.clear(classes)
This method is for internal use only.
[ GitHub ]
# File 'activesupport/lib/active_support/descendants_tracker.rb', line 78
def clear(classes) # :nodoc: raise "DescendantsTracker.clear was disabled because config.enable_reloading is false" if @clear_disabled classes.each do |klass| @excluded_descendants << klass klass.descendants.each do |descendant| @excluded_descendants << descendant end end end
.descendants(klass)
[ GitHub ]# File 'activesupport/lib/active_support/descendants_tracker.rb', line 102
def descendants(klass) klass.descendants end
.disable_clear!
This method is for internal use only.
[ GitHub ]
# File 'activesupport/lib/active_support/descendants_tracker.rb', line 69
def disable_clear! # :nodoc: unless @clear_disabled @clear_disabled = true ReloadedClassesFiltering.remove_method(:subclasses) ReloadedClassesFiltering.remove_method(:descendants) @excluded_descendants = nil end end
.reject!(classes)
This method is for internal use only.
[ GitHub ]
# File 'activesupport/lib/active_support/descendants_tracker.rb', line 89
def reject!(classes) # :nodoc: if @excluded_descendants classes.reject! { |d| @excluded_descendants.include?(d) } end classes end
.subclasses(klass)
[ GitHub ]# File 'activesupport/lib/active_support/descendants_tracker.rb', line 98
def subclasses(klass) klass.subclasses end
Instance Method Details
#descendants
[ GitHub ]# File 'activesupport/lib/active_support/descendants_tracker.rb', line 107
def descendants subclasses = DescendantsTracker.reject!(self.subclasses) subclasses.concat(subclasses.flat_map(&:descendants)) end