Sha256: 8896b092172d3c3e5264c2d8a9e60c2b48016213af0047558b632a5bff6f7abe

Contents?: true

Size: 920 Bytes

Versions: 9

Compression:

Stored size: 920 Bytes

Contents

# frozen_string_literal: true

require_relative '../operation'
require_relative 'resource'

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

        private

        def operate
          if resource
            success
          else
            failure('Not found')
          end
        end

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

        def success
          super(resource)
        end

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

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
ledger_sync-domains-1.2.1 lib/ledger_sync/domains/operation/find.rb
ledger_sync-domains-1.2.0 lib/ledger_sync/domains/operation/find.rb
ledger_sync-domains-1.1.4 lib/ledger_sync/domains/operation/find.rb
ledger_sync-domains-1.1.3 lib/ledger_sync/domains/operation/find.rb
ledger_sync-domains-1.1.1 lib/ledger_sync/domains/operation/find.rb
ledger_sync-domains-1.1.0 lib/ledger_sync/domains/operation/find.rb
ledger_sync-domains-1.0.5 lib/ledger_sync/domains/operation/find.rb
ledger_sync-domains-1.0.4 lib/ledger_sync/domains/operation/find.rb
ledger_sync-domains-1.0.3 lib/ledger_sync/domains/operation/find.rb