Class: Releaf::Content::Node::Move

Inherits:
Object
  • Object
show all
Includes:
Service
Defined in:
app/services/releaf/content/node/move.rb

Instance Method Summary collapse

Methods included from Service

#add_error_and_raise

Instance Method Details

#callObject



7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'app/services/releaf/content/node/move.rb', line 7

def call
  return node if node.parent_id.to_i == parent_id

  node.class.transaction do
    Releaf::Content::Node::SaveUnderParent.call(node: node, parent_id: parent_id)

    node.descendants.each do |descendant_node|
      next if descendant_node.valid?
      add_error_and_raise("descendant invalid")
    end
  end

  node
end