Module: Compo::Mixins::Movable

Included in:
Branches::Branch
Defined in:
lib/compo/mixins/movable.rb

Overview

Helper mixin for objects that can be moved into other objects

This mixin defines a method, #move_to, which handles removing a child from its current parent and adding it to a new one.

It expects the current parent to be reachable from #parent.

Instance Method Summary collapse

Instance Method Details

#move_to(new_parent, new_id) ⇒ self

Moves this model object to a new parent with a new ID

Examples:

Moves the object to a new parent.

movable.move_to(parent, :id)

Moves the object out of its parent (deleting it, if there are

no other live references).
movable.move_to(nil, nil)

Parameters:

  • new_parent (ModelObject)

    The new parent for this object (can be nil).

  • new_id (Object)

    The new ID under which the object will exist in the parent.

Returns:

  • (self)


25
26
27
28
29
# File 'lib/compo/mixins/movable.rb', line 25

def move_to(new_parent, new_id)
  move_from_old_parent
  move_to_new_parent(new_parent, new_id)
  self
end