Sha256: c2bb94c20a7a2a39e550c87e105fb390d12d29e92da1387f0c8c7d397f597dcc

Contents?: true

Size: 996 Bytes

Versions: 6

Compression:

Stored size: 996 Bytes

Contents

# frozen_string_literal: true

require_relative '../operation'
require_relative 'resource'

module LedgerSync
  module Domains
    class Operation
      class Add < Resource
        class Contract < LedgerSync::Ledgers::Contract
          params do
            required(:data).value(:hash)
          end
        end

        private

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

        def resource
          @resource ||= resource_class.new(params[:data])
        end

        def success
          super(resource)
        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/add.rb
ledger_sync-domains-1.2.0 lib/ledger_sync/domains/operation/add.rb
ledger_sync-domains-1.1.4 lib/ledger_sync/domains/operation/add.rb
ledger_sync-domains-1.1.3 lib/ledger_sync/domains/operation/add.rb
ledger_sync-domains-1.1.1 lib/ledger_sync/domains/operation/add.rb
ledger_sync-domains-1.1.0 lib/ledger_sync/domains/operation/add.rb