Class: ServiCraft::Destroy

Inherits:
Object
  • Object
show all
Defined in:
lib/servi_craft/destroy.rb

Overview

Destroy Record Service

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(record) ⇒ Destroy

Returns a new instance of Destroy.



10
11
12
13
# File 'lib/servi_craft/destroy.rb', line 10

def initialize(record)
  @record = record
  @response = ::EchoCraft::ServiceObjects::Destroy.new(@record)
end

Instance Attribute Details

#responseObject (readonly)

Returns the value of attribute response.



8
9
10
# File 'lib/servi_craft/destroy.rb', line 8

def response
  @response
end

Instance Method Details

#call(before_destroy: proc {}, after_successful_destroy: proc {}, after_failed_destroy: proc {}, finally: proc {}) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/servi_craft/destroy.rb', line 15

def call(before_destroy: proc {},
         after_successful_destroy: proc {},
         after_failed_destroy: proc {},
         finally: proc {})

  before_destroy.call
  process_record_destroy(after_successful_destroy: after_successful_destroy,
                         after_failed_destroy: after_failed_destroy)
  finally.call

  @response
rescue StandardError => e
  puts "#{e.class}: #{e.message}"
  puts e.backtrace.join("\n")
end