Sha256: a4dced11f16096ff40dce76365c31c8d3657ebd78147389417c5ad358d045670

Contents?: true

Size: 786 Bytes

Versions: 4

Compression:

Stored size: 786 Bytes

Contents

# frozen_string_literal: true

module Pragma
  module Operation
    # Finds an existing record, destroys it and responds 204 No Content.
    #
    # @author Alessandro Desantis
    class Destroy < Pragma::Operation::Base
      step Macro::Classes()
      step Macro::Model(:find_by)
      step Macro::Policy()
      step :destroy!, name: 'destroy'
      step :respond!, name: 'respond'

      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

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

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
pragma-2.5.0 lib/pragma/operation/destroy.rb
pragma-2.4.0 lib/pragma/operation/destroy.rb
pragma-2.3.0 lib/pragma/operation/destroy.rb
pragma-2.2.0 lib/pragma/operation/destroy.rb