Sha256: 09a23d5d9e97fb3a3c6da19fbb9f2197f557044f21bfd3a5aacca643ca872bdc

Contents?: true

Size: 856 Bytes

Versions: 8

Compression:

Stored size: 856 Bytes

Contents

# frozen_string_literal: true

require_relative '../operation'
require_relative 'resource'

module LedgerSync
  module Domains
    class Operation
      class Add < Resource
        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(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

8 entries across 8 versions & 1 rubygems

Version Path
ledger_sync-domains-1.0.5 lib/ledger_sync/domains/operation/add.rb
ledger_sync-domains-1.0.4 lib/ledger_sync/domains/operation/add.rb
ledger_sync-domains-1.0.3 lib/ledger_sync/domains/operation/add.rb
ledger_sync-domains-1.0.2 lib/ledger_sync/domains/operation/add.rb
ledger_sync-domains-1.0.1 lib/ledger_sync/domains/operation/add.rb
ledger_sync-domains-1.0.0 lib/ledger_sync/domains/operation/add.rb
ledger_sync-domains-1.0.0.rc10 lib/ledger_sync/domains/operation/add.rb
ledger_sync-domains-1.0.0.rc9 lib/ledger_sync/domains/operation/add.rb