Sha256: ac527c24925af02734773de0cc3d7aec686c441bc5b288ba987b99b61e623e14

Contents?: true

Size: 959 Bytes

Versions: 4

Compression:

Stored size: 959 Bytes

Contents

# frozen_string_literal: true

require_relative '../operation'

module LedgerSync
  module Domains
    class Operation
      class Find
        include LedgerSync::Domains::Operation::Mixin

        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.find_by(id: params[:id])
        end

        def success
          super(
            serialize(resource: resource)
          )
        end

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

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
ledger_sync-domains-1.0.0.rc4 lib/ledger_sync/domains/operation/find.rb
ledger_sync-domains-1.0.0.rc3 lib/ledger_sync/domains/operation/find.rb
ledger_sync-domains-1.0.0.rc2 lib/ledger_sync/domains/operation/find.rb
ledger_sync-domains-1.0.0.rc1 lib/ledger_sync/domains/operation/find.rb