Sha256: 5964be85a1ed6d271fa5eeb0b6a62224e72b02c952809ff8248e486a714c2e3d

Contents?: true

Size: 1.14 KB

Versions: 3

Compression:

Stored size: 1.14 KB

Contents

# frozen_string_literal: true

require_relative '../operation'
require_relative 'resource'

module LedgerSync
  module Domains
    class Operation
      class Remove < Resource
        class Contract < LedgerSync::Ledgers::Contract
          params do
            required(:id).filled(:integer)
            required(:limit).value(:hash)
          end
        end

        private

        def operate
          return failure('Resource not found') unless resource

          if resource.destroy
            success
          else
            failure(
              'Please review the problems below:',
              data: serialize(resource: resource)
            )
          end
        end

        def resource
          @resource ||= resource_class.where(params[:limit]).find_by(id: params[:id])
        end

        def success
          super(
            true
          )
        end

        def failure(message, data: nil)
          super(
              LedgerSync::Error::OperationError.new(
                operation: self,
                message: message,
                response: data
              )
          )
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
ledger_sync-domains-1.0.5 lib/ledger_sync/domains/operation/remove.rb
ledger_sync-domains-1.0.4 lib/ledger_sync/domains/operation/remove.rb
ledger_sync-domains-1.0.3 lib/ledger_sync/domains/operation/remove.rb