Class: ActiveSupport::DescendantsTracker::DescendantsArray

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/active_support/descendants_tracker.rb

Overview

DescendantsArray is an array that contains weak references to classes.

Instance Method Summary collapse

Methods included from Enumerable

#as_json, #compact_blank, #exclude?, #excluding, #including, #index_by, #index_with, #many?, #pick, #pluck, #sum, #without

Constructor Details

#initializeDescendantsArray

Returns a new instance of DescendantsArray.



73
74
75
# File 'lib/active_support/descendants_tracker.rb', line 73

def initialize
  @refs = []
end

Instance Method Details

#<<(klass) ⇒ Object



81
82
83
# File 'lib/active_support/descendants_tracker.rb', line 81

def <<(klass)
  @refs << WeakRef.new(klass)
end

#cleanup!Object



99
100
101
# File 'lib/active_support/descendants_tracker.rb', line 99

def cleanup!
  @refs.delete_if { |ref| !ref.weakref_alive? }
end

#eachObject



85
86
87
88
89
90
91
92
93
# File 'lib/active_support/descendants_tracker.rb', line 85

def each
  @refs.reject! do |ref|
    yield ref.__getobj__
    false
  rescue WeakRef::RefError
    true
  end
  self
end

#initialize_copy(orig) ⇒ Object



77
78
79
# File 'lib/active_support/descendants_tracker.rb', line 77

def initialize_copy(orig)
  @refs = @refs.dup
end

#refs_sizeObject



95
96
97
# File 'lib/active_support/descendants_tracker.rb', line 95

def refs_size
  @refs.size
end

#reject!Object



103
104
105
106
107
108
109
# File 'lib/active_support/descendants_tracker.rb', line 103

def reject!
  @refs.reject! do |ref|
    yield ref.__getobj__
  rescue WeakRef::RefError
    true
  end
end