Sha256: 49b2d56c1d3d94239fc1fde15008b9daccfe5faa1ee456af6a6c7d48cfd2739b

Contents?: true

Size: 1.1 KB

Versions: 5

Compression:

Stored size: 1.1 KB

Contents

module LedgerSync
  module Adaptors
    module Test
      module Customer
        module Operations
          class Upsert < Operation::Upsert
            class Contract < LedgerSync::Adaptors::Contract
              params do
                required(:ledger_id).maybe(:string)
                optional(:email).maybe(:string)
                required(:name).filled(:string)
                optional(:phone_number).maybe(:string)
              end
            end

            private

            def build
              op =  if customer_exists_in_ledger?
                      Update.new(adaptor: adaptor, resource: resource)
                    else
                      Create.new(adaptor: adaptor, resource: resource)
                    end
              add_root_operation(op)
            end

            def find_result
              @find_result ||= Find.new(
                adaptor: adaptor,
                resource: resource
              ).perform
            end

            def customer_exists_in_ledger?
              find_result.success?
            end
          end
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
ledger_sync-1.0.10 lib/ledger_sync/adaptors/test/customer/operations/upsert.rb
ledger_sync-1.0.9 lib/ledger_sync/adaptors/test/customer/operations/upsert.rb
ledger_sync-1.0.3 lib/ledger_sync/adaptors/test/customer/operations/upsert.rb
ledger_sync-1.0.2 lib/ledger_sync/adaptors/test/customer/operations/upsert.rb
ledger_sync-1.0.0 lib/ledger_sync/adaptors/test/customer/operations/upsert.rb