Sha256: 818bc3f75428a1c03bcf1f55007628e14946297a60c061aa8d21890d407f8234

Contents?: true

Size: 917 Bytes

Versions: 4

Compression:

Stored size: 917 Bytes

Contents

# frozen_string_literal: true

require_relative '../operation'

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

        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)
        end

        def success
          super(
            serialize(resource: 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

4 entries across 4 versions & 1 rubygems

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