Module: Reactor::Legacy::Base

Defined in:
lib/reactor/legacy.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



6
7
8
# File 'lib/reactor/legacy.rb', line 6

def self.included(base)
  base.extend(ClassMethods)
end

Instance Method Details

#delete_children!(options = {}) ⇒ Object

removes CMS objects underneath current object

Parameters:

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :no_children (Object)

    if true prevents deletion unless there are no children

  • :img_children_only (Object)

    if true prevents deletion unless there are exclusively img children

  • :children (Array)

    if true prevents deletion if there are other children besides the specified ones (array of names)



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/reactor/legacy.rb', line 14

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