Module: Compo::ParentTracker
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.
Instance Attribute Summary collapse
-
#parent ⇒ Composite
readonly
Gets this object’s current ID.
Instance Method Summary collapse
-
#initialize ⇒ Void
Initialises the ParentTracker.
-
#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
39 40 41 |
# File 'lib/compo/parent_tracker.rb', line 39 def parent @parent end |
Instance Method Details
#initialize ⇒ Void
Initialises the ParentTracker
This constructor sets the tracker up so it initially has an instance of Parentless as its ‘parent’.
23 24 25 26 |
# File 'lib/compo/parent_tracker.rb', line 23 def initialize super() remove_parent end |
#remove_parent ⇒ void
This method returns an undefined value.
Blanks out this object’s parent and ID function
76 77 78 |
# File 'lib/compo/parent_tracker.rb', line 76 def remove_parent update_parent(Parentless.new, -> { nil }) end |
#update_parent(new_parent, new_id_function) ⇒ void
This method returns an undefined value.
Updates this object’s parent and ID function
61 62 63 64 65 66 67 |
# File 'lib/compo/parent_tracker.rb', line 61 def update_parent(new_parent, new_id_function) fail 'Parent cannot be nil: use #remove_parent.' if new_parent.nil? fail 'ID function cannot be nil: use -> { nil }.' if new_id_function.nil? @parent = new_parent @id_function = new_id_function end |