Spec-Zone.ru › Ruby on Rails 7.0

модуль ActiveSupport::DescendantsTracker

Этот модуль предоставляет внутреннюю реализацию отслеживания потомков, которая быстрее, чем итерация по ObjectSpace.

Публичные методы класса

descendants(klass) Показать исходный код
# File activesupport/lib/active_support/descendants_tracker.rb, line 62
def descendants(klass)
  klass.descendants
end
direct_descendants(klass) Показать исходный код
# 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
store_inherited(klass, descendant) Показать исходный код
# File activesupport/lib/active_support/descendants_tracker.rb, line 138
def store_inherited(klass, descendant)
  (@@direct_descendants[klass] ||= DescendantsArray.new) << descendant
end

Этот метод — единственный, который не является потокобезопасным, но вызывается только во время фазы жадного загрузки.

subclasses(klass) Показать исходный код
# File activesupport/lib/active_support/descendants_tracker.rb, line 58
def subclasses(klass)
  klass.subclasses
end

Публичные методы экземпляра

descendants() Показать исходный код
# File activesupport/lib/active_support/descendants_tracker.rb, line 88
def descendants
  subclasses.concat(subclasses.flat_map(&:descendants))
end
direct_descendants() Показать исходный код
# 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
inherited(base) Показать исходный код
# File activesupport/lib/active_support/descendants_tracker.rb, line 153
def inherited(base)
  DescendantsTracker.store_inherited(self, base)
  super
end
Вызывает метод суперкласса
subclasses() Показать исходный код
# File activesupport/lib/active_support/descendants_tracker.rb, line 82
def subclasses
  subclasses = super
  subclasses.reject! { |d| @@excluded_descendants[d] }
  subclasses
end
Вызывает метод суперкласса

© 2004–2021 David Heinemeier Hansson
Licensed under the MIT License.

Spec-Zone.ru

Настройки Оффлайн Что нового Помощь О нас
Spec-Zone .ru
спецификации, руководства, описания, API