Sha256: afe767a755a0ece1e2d2fd0a3fcf0f5fc08ac52977dae09fc7cd912421ee9c0e

Contents?: true

Size: 943 Bytes

Versions: 3

Compression:

Stored size: 943 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.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

3 entries across 3 versions & 1 rubygems

Version Path
ledger_sync-domains-1.0.0.rc8 lib/ledger_sync/domains/operation/find.rb
ledger_sync-domains-1.0.0.rc7 lib/ledger_sync/domains/operation/find.rb
ledger_sync-domains-1.0.0.rc6 lib/ledger_sync/domains/operation/find.rb