Module: Compo::ParentTracker
- Extended by:
- Forwardable
- Included in:
- ArrayBranch, HashBranch, Leaf
- Defined in:
- lib/compo/parent_tracker.rb
Overview
Basic implementation of parent tracking as a mixin
This implements #parent, #update_parent and #remove_parent to track the current parent and ID function as instance variables. It also implements #parent, and #id in terms of the ID function.
Subclasses should call #remove_parent in their #initialize methods, to set the parent and ID function to their default, empty values.
Instance Attribute Summary collapse
-
#parent ⇒ Composite
readonly
Gets this object’s current ID.
Instance Method Summary collapse
-
#remove_parent ⇒ void
Blanks out this object’s parent and ID function.
-
#update_parent(new_parent, new_id_function) ⇒ void
Updates this object’s parent and ID function.
Instance Attribute Details
#parent ⇒ Composite (readonly)
Gets this object’s current ID
26 27 28 |
# File 'lib/compo/parent_tracker.rb', line 26 def parent @parent end |
Instance Method Details
#remove_parent ⇒ void
This method returns an undefined value.
Blanks out this object’s parent and ID function
60 61 62 |
# File 'lib/compo/parent_tracker.rb', line 60 def remove_parent update_parent(nil, -> { nil }) end |
#update_parent(new_parent, new_id_function) ⇒ void
This method returns an undefined value.
Updates this object’s parent and ID function
48 49 50 51 |
# File 'lib/compo/parent_tracker.rb', line 48 def update_parent(new_parent, new_id_function) @parent = new_parent @id_function = new_id_function end |