Sha256: e6931ee16104db0314a81947b4d0a421f99ee74c97120c7101eacdc6ccab85ab

Contents?: true

Size: 901 Bytes

Versions: 3

Compression:

Stored size: 901 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(
            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

3 entries across 3 versions & 1 rubygems

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