Module: MotionSupport::DescendantsTracker
- Defined in:
- motion/descendants_tracker.rb
Overview
This module provides an internal implementation to track descendants which is faster than iterating through ObjectSpace.
Constant Summary collapse
- @@direct_descendants =
{}
Class Method Summary collapse
- .clear ⇒ Object
- .descendants(klass) ⇒ Object
- .direct_descendants(klass) ⇒ Object
-
.store_inherited(klass, descendant) ⇒ Object
This is the only method that is not thread safe, but is only ever called during the eager loading phase.
Instance Method Summary collapse
Class Method Details
.clear ⇒ Object
18 19 20 |
# File 'motion/descendants_tracker.rb', line 18 def clear @@direct_descendants.clear end |
.descendants(klass) ⇒ Object
12 13 14 15 16 |
# File 'motion/descendants_tracker.rb', line 12 def descendants(klass) arr = [] accumulate_descendants(klass, arr) arr end |
.direct_descendants(klass) ⇒ Object
8 9 10 |
# File 'motion/descendants_tracker.rb', line 8 def direct_descendants(klass) @@direct_descendants[klass] || [] end |
.store_inherited(klass, descendant) ⇒ Object
This is the only method that is not thread safe, but is only ever called during the eager loading phase.
24 25 26 |
# File 'motion/descendants_tracker.rb', line 24 def store_inherited(klass, descendant) (@@direct_descendants[klass] ||= []) << descendant end |
Instance Method Details
#descendants ⇒ Object
46 47 48 |
# File 'motion/descendants_tracker.rb', line 46 def descendants DescendantsTracker.descendants(self) end |
#direct_descendants ⇒ Object
42 43 44 |
# File 'motion/descendants_tracker.rb', line 42 def direct_descendants DescendantsTracker.direct_descendants(self) end |
#inherited(base) ⇒ Object
37 38 39 40 |
# File 'motion/descendants_tracker.rb', line 37 def inherited(base) DescendantsTracker.store_inherited(self, base) super end |