Sha256: c038104ff99faca7e4576bb0fd84d961fb24c5ca44692a7e5810d91799413fe5

Contents?: true

Size: 1.13 KB

Versions: 6

Compression:

Stored size: 1.13 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

6 entries across 6 versions & 1 rubygems

Version Path
ledger_sync-domains-1.2.1 lib/ledger_sync/domains/operation/remove.rb
ledger_sync-domains-1.2.0 lib/ledger_sync/domains/operation/remove.rb
ledger_sync-domains-1.1.4 lib/ledger_sync/domains/operation/remove.rb
ledger_sync-domains-1.1.3 lib/ledger_sync/domains/operation/remove.rb
ledger_sync-domains-1.1.1 lib/ledger_sync/domains/operation/remove.rb
ledger_sync-domains-1.1.0 lib/ledger_sync/domains/operation/remove.rb