Class: Collavre::Creatives::DestroyService

Inherits:
Object
  • Object
show all
Defined in:
app/services/collavre/creatives/destroy_service.rb

Overview

Handles creative destruction with optional recursive child deletion.

Instance Method Summary collapse

Constructor Details

#initialize(creative:, user:, delete_with_children: false) ⇒ DestroyService

Returns a new instance of DestroyService.



7
8
9
10
11
# File 'app/services/collavre/creatives/destroy_service.rb', line 7

def initialize(creative:, user:, delete_with_children: false)
  @creative = creative
  @user = user
  @delete_with_children = delete_with_children
end

Instance Method Details

#callObject



13
14
15
16
17
18
19
20
21
22
# File 'app/services/collavre/creatives/destroy_service.rb', line 13

def call
  if @delete_with_children
    destroy_descendants_recursively(@creative)
  else
    reparent_children
  end

  CreativeShare.where(creative: @creative).destroy_all
  @creative.destroy
end