Class: Moogle::Commands::DestroyTarget

Inherits:
Object
  • Object
show all
Includes:
Serf::Command
Defined in:
lib/moogle/commands/destroy_target.rb

Instance Method Summary collapse

Instance Method Details

#callObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/moogle/commands/destroy_target.rb', line 16

def call
  target_model = opts :target_model, Moogle::Target
  event_class = opts :event_class, Moogle::Events::TargetDestroyed

  target_id = request.target_id
  target = target_model.get target_id

  # We only attempt to destroy the link if it exists.
  # We raise an error if we are unable to destroy an existing link.
  raise 'Unable to destroy target' unless target.destroy if target

  return event_class.new(
    request.create_child_uuids.merge(target_id: target_id))
rescue => e
  e.extend Moogle::Error
  raise e
end