Sha256: 1e5d34d422e1a3d3768abc25048a348094b218367b3315af23ae73857dbcc903

Contents?: true

Size: 1.32 KB

Versions: 8

Compression:

Stored size: 1.32 KB

Contents

# frozen_string_literal: true

require_relative '../operation'

module LedgerSync
  module Ledgers
    module NetSuite
      class Operation
        class Update
          include NetSuite::Operation::Mixin

          private

          def update_in_ledger
            case response.status
            when 200..299
              LedgerSync::Result.Success(response)
            else
              failure(
                Error::OperationError.new(
                  operation: self,
                  response: response
                )
              )
            end
          end

          def find
            resource.ledger_id = ledger_id

            self.class.operations_module::Find.new(
              client: client,
              resource: resource
            ).perform
          end

          def operate
            update_in_ledger
              .and_then { success }
          end

          def response
            @response ||= client.patch(
              body: serializer.serialize(resource: resource),
              path: ledger_resource_path
            )
          end

          def success
            find.and_then do |find_result|
              super(
                resource: find_result.resource,
                response: response
              )
            end
          end
        end
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
ledger_sync-1.6.0 lib/ledger_sync/ledgers/netsuite/operation/update.rb
ledger_sync-1.5.2 lib/ledger_sync/ledgers/netsuite/operation/update.rb
ledger_sync-1.5.1 lib/ledger_sync/ledgers/netsuite/operation/update.rb
ledger_sync-1.5.0 lib/ledger_sync/ledgers/netsuite/operation/update.rb
ledger_sync-1.4.4 lib/ledger_sync/ledgers/netsuite/operation/update.rb
ledger_sync-1.4.2 lib/ledger_sync/ledgers/netsuite/operation/update.rb
ledger_sync-1.4.1 lib/ledger_sync/ledgers/netsuite/operation/update.rb
ledger_sync-1.4.0 lib/ledger_sync/ledgers/netsuite/operation/update.rb