Class: Pragma::Operation::Destroy

Inherits:
Base
  • Object
show all
Defined in:
lib/pragma/operation/destroy.rb

Overview

Finds an existing record, destroys it and responds 204 No Content.

Author:

  • Alessandro Desantis

Instance Method Summary collapse

Instance Method Details

#destroy!(_options, model:) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/pragma/operation/destroy.rb', line 15

def destroy!(_options, model:, **)
  unless model.destroy
    options['result.response'] = Response::UnprocessableEntity.new(
      errors: model.errors
    ).decorate_with(Decorator::Error)

    return false
  end

  true
end

#respond!(options) ⇒ Object



27
28
29
# File 'lib/pragma/operation/destroy.rb', line 27

def respond!(options)
  options['result.response'] = Response::NoContent.new
end