module Reactor::Legacy::Base

Public Class Methods

included(base) click to toggle source
# File lib/reactor/legacy.rb, line 5
def self.included(base)
  base.extend(ClassMethods)
end

Public Instance Methods

delete_children!(options={}) click to toggle source

removes CMS objects underneath current object @option options :no_children if true prevents deletion unless there are no children @option options :img_children_only if true prevents deletion unless there are exclusively img children @option options [Array] :children if true prevents deletion if there are other children besides the specified ones (array of names)

# File lib/reactor/legacy.rb, line 13
def delete_children!(options={})
  # TODO: provide better discrimination mechanisms (blocks?)
  f_nochild   = options.delete(:no_children)
  f_imgchild  = options.delete(:img_children_only)
  f_children  = options.delete(:children)

  mychildren  = self.children
  image_children, other_children = mychildren.partition {|obj| obj.obj_class == 'Image'}

  # are there any links pointing to this container
  return false if has_super_links?
  # is the flag set and are there any children
  return false if f_nochild && !mychildren.empty?
  # is the flag set and are there any children besides images
  return false if f_imgchild && !other_children.empty?
  # is the flag set and are there any children besides the specified ones
  return false if f_children && !((mychildren.map(&:name) - f_children).empty?)

  # check children for any links pointing to them
  return false if mychildren.detect(&:has_super_links?)
  # check if there are any grandchildren
  return false if mychildren.detect {|child| !child.children.empty?}

  # delete children
  mychildren.each(&:destroy)
  return true
end