Sha256: e45dd8107efca8d0a2dec41ab06ae8435e46784a05c19ebad1281ef6af7f8723

Contents?: true

Size: 1.08 KB

Versions: 43

Compression:

Stored size: 1.08 KB

Contents

require 'active_support/dependencies'

module ActiveSupport
  # This module provides an internal implementation to track descendants
  # which is faster than iterating through ObjectSpace.
  module DescendantsTracker
    @@direct_descendants = Hash.new { |h, k| h[k] = [] }

    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
      @@direct_descendants.each do |klass, descendants|
        if ActiveSupport::Dependencies.autoloaded?(klass)
          @@direct_descendants.delete(klass)
        else
          descendants.reject! { |v| ActiveSupport::Dependencies.autoloaded?(v) }
        end
      end
    end

    def inherited(base)
      self.direct_descendants << base
      super
    end

    def direct_descendants
      DescendantsTracker.direct_descendants(self)
    end

    def descendants
      DescendantsTracker.descendants(self)
    end
  end
end

Version data entries

43 entries across 43 versions & 3 rubygems

Version Path
social_url_stats-0.0.1 vendor/ruby/1.9.1/gems/activesupport-3.0.0/lib/active_support/descendants_tracker.rb
activesupport-3.0.20 lib/active_support/descendants_tracker.rb
activesupport-3.0.19 lib/active_support/descendants_tracker.rb
activesupport-3.0.18 lib/active_support/descendants_tracker.rb
activesupport-3.0.17 lib/active_support/descendants_tracker.rb
activesupport-3.0.16 lib/active_support/descendants_tracker.rb
activesupport-3.0.15 lib/active_support/descendants_tracker.rb
activesupport-3.0.14 lib/active_support/descendants_tracker.rb
activesupport-3.0.13 lib/active_support/descendants_tracker.rb
activesupport-3.0.13.rc1 lib/active_support/descendants_tracker.rb
activesupport-3.0.12 lib/active_support/descendants_tracker.rb
activesupport-3.0.12.rc1 lib/active_support/descendants_tracker.rb
activesupport-3.0.11 lib/active_support/descendants_tracker.rb
messagebus_ruby_api-0.4.7 spec/ruby/1.9.1/gems/activesupport-3.0.9/lib/active_support/descendants_tracker.rb
messagebus_ruby_api-0.4.4 spec/ruby/1.9.1/gems/activesupport-3.0.9/lib/active_support/descendants_tracker.rb
activesupport-3.0.10 lib/active_support/descendants_tracker.rb
activesupport-3.0.10.rc1 lib/active_support/descendants_tracker.rb
activesupport-3.0.9 lib/active_support/descendants_tracker.rb
activesupport-3.0.9.rc5 lib/active_support/descendants_tracker.rb
activesupport-3.0.9.rc4 lib/active_support/descendants_tracker.rb