lib/compo/parent_tracker.rb in compo-0.2.0 vs lib/compo/parent_tracker.rb in compo-0.3.0

- old
+ new

@@ -5,16 +5,18 @@ # 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. module ParentTracker extend Forwardable + def initialize + super() + remove_parent + end + # Gets this object's current ID # # @api public # @example Gets the object's parent while it has none. # parent_tracker.parent @@ -45,9 +47,12 @@ # @example Update this Leaf's parent and ID function. # parent_tracker.update_parent(new_parent, new_id_function) # # @return [void] 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 # Blanks out this object's parent and ID function