Module: ActiveSupport::DescendantsTracker
Relationships & Source Files | |
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::InternalMetadata,
ActiveRecord::Railtie,
ActiveRecord::SchemaMigration,
ActiveStorage::Engine,
ActiveSupport::Railtie,
I18n::Railtie,
::Rails::Application ,
Rails::ApplicationController,
::Rails::Engine ,
Rails::InfoController,
Rails::MailersController,
::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.
Class Method Summary
- .clear
- .descendants(klass)
- .direct_descendants(klass) (also: .subclasses)
-
.store_inherited(klass, descendant)
This is the only method that is not thread safe, but is only ever called during the eager loading phase.
-
.subclasses(klass)
Alias for .direct_descendants.
Instance Method Summary
- #descendants
- #direct_descendants (also: #subclasses)
- #inherited(base)
-
#subclasses
Alias for #direct_descendants.
Class Method Details
.clear
[ GitHub ]# File 'activesupport/lib/active_support/descendants_tracker.rb', line 24
def clear if defined? ActiveSupport::Dependencies @@direct_descendants.each do |klass, descendants| if Dependencies.autoloaded?(klass) @@direct_descendants.delete(klass) else descendants.reject! { |v| Dependencies.autoloaded?(v) } end end else @@direct_descendants.clear end end
.descendants(klass)
[ GitHub ]# File 'activesupport/lib/active_support/descendants_tracker.rb', line 18
def descendants(klass) arr = [] accumulate_descendants(klass, arr) arr end
.direct_descendants(klass) Also known as: .subclasses
[ GitHub ]# File 'activesupport/lib/active_support/descendants_tracker.rb', line 12
def direct_descendants(klass) descendants = @@direct_descendants[klass] descendants ? descendants.to_a : [] end
.store_inherited(klass, descendant)
This is the only method that is not thread safe, but is only ever called during the eager loading phase.
# File 'activesupport/lib/active_support/descendants_tracker.rb', line 40
def store_inherited(klass, descendant) (@@direct_descendants[klass] ||= DescendantsArray.new) << descendant end
.subclasses(klass)
Alias for .direct_descendants.
# File 'activesupport/lib/active_support/descendants_tracker.rb', line 16
alias_method :subclasses, :direct_descendants
Instance Method Details
#descendants
[ GitHub ]# File 'activesupport/lib/active_support/descendants_tracker.rb', line 65
def descendants DescendantsTracker.descendants(self) end
#direct_descendants Also known as: #subclasses
[ GitHub ]# File 'activesupport/lib/active_support/descendants_tracker.rb', line 60
def direct_descendants DescendantsTracker.direct_descendants(self) end
#inherited(base)
[ GitHub ]# File 'activesupport/lib/active_support/descendants_tracker.rb', line 55
def inherited(base) DescendantsTracker.store_inherited(self, base) super end
#subclasses
Alias for #direct_descendants.
# File 'activesupport/lib/active_support/descendants_tracker.rb', line 63
alias_method :subclasses, :direct_descendants