Module: CassandraMapper::Support::DescendantsTracker
- Defined in:
- lib/cassandra_mapper/support/descendants_tracker.rb
Overview
This module provides an internal implementation to track descendants which is faster than iterating through ObjectSpace.
Constant Summary collapse
- @@descendants =
Hash.new { |h, k| h[k] = [] }
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.clear ⇒ Object
14 15 16 17 18 19 20 21 22 |
# File 'lib/cassandra_mapper/support/descendants_tracker.rb', line 14 def self.clear @@descendants.each do |klass, descendants| if CassandraMapper::Support::Dependencies.autoloaded?(klass) @@descendants.delete(klass) else descendants.reject! { |v| CassandraMapper::Support::Dependencies.autoloaded?(v) } end end end |
.descendants ⇒ Object
10 11 12 |
# File 'lib/cassandra_mapper/support/descendants_tracker.rb', line 10 def self.descendants @@descendants end |
Instance Method Details
#descendants ⇒ Object
33 34 35 36 37 38 |
# File 'lib/cassandra_mapper/support/descendants_tracker.rb', line 33 def descendants @@descendants[self].inject([]) do |descendants, klass| descendants << klass descendants.concat klass.descendants end end |
#direct_descendants ⇒ Object
29 30 31 |
# File 'lib/cassandra_mapper/support/descendants_tracker.rb', line 29 def direct_descendants @@descendants[self] end |
#inherited(base) ⇒ Object
24 25 26 27 |
# File 'lib/cassandra_mapper/support/descendants_tracker.rb', line 24 def inherited(base) self.direct_descendants << base super end |