Sha256: 00a0ba9a1866723672a92f2ef96367e780576f88d6bdd150b04876cfd49f157c

Contents?: true

Size: 572 Bytes

Versions: 4

Compression:

Stored size: 572 Bytes

Contents

module Transactionable
  module BalancedCustomer
    extend ActiveSupport::Concern

    included do
      has_one :remote_customer, as: :local_entity, dependent: :destroy, class_name: "Transactionable::RemoteCustomer"
      
      def sync_customer
        if remote_customer
          remote_customer.build_or_update_remote
        else
          Transactionable::RemoteCustomer.create(local_entity: self)
        end
      end

      def remote
        if remote_customer && remote_customer.synced?
          remote_customer.fetch
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
transactionable-0.3.1 lib/transactionable/balanced_customer.rb
transactionable-0.3.0 lib/transactionable/balanced_customer.rb
transactionable-0.2.0 lib/transactionable/balanced_customer.rb
transactionable-0.1.0 lib/transactionable/balanced_customer.rb