Sha256: 0109ed39961361d281ee3e6ef00c68d8a5f22a4be11456fff48b2ae453dadf1b
Contents?: true
Size: 1.06 KB
Versions: 11
Compression:
Stored size: 1.06 KB
Contents
module OrderedTree module InstanceMethods module Destroy ## Destroy Methods # sends immediate children to the 'roots' list, then destroy's self def destroy_and_orphan_children self.class.transaction do orphan_children self.destroy end end # hands immediate children of to it's parent, then destroy's self def destroy_and_parent_adopts_children self.class.transaction do parent_adopts_children self.destroy end end def reorder_children self.class.transaction do children(true).each do |child| new_position = children.index(child) + 1 child.update_attribute(order_column, new_position) if (child.position_in_list != new_position) end end end protected def destroy_descendants #:nodoc: # before_destroy callback (recursive) @old_parent = self.class.find(self).parent || 'root' self.children(true).each{|child| child.destroy} end end end end
Version data entries
11 entries across 11 versions & 1 rubygems