Sha256: 9137d521c7b3ec935f77dca0e8f1bebbffe0894d2e0e55130d130fda99f7a67d

Contents?: true

Size: 778 Bytes

Versions: 4

Compression:

Stored size: 778 Bytes

Contents

module Transactionable
  class RemoteEntity < ActiveRecord::Base
    belongs_to :local_entity, polymorphic: true

    before_destroy :destroy_remote

    def build_or_update_remote
      raise "Not Implemented"
    end

    def service_name
      read_attribute(:service_name) || "Balanced"
    end

    def build_remote
      raise "Not Implemented"
    end

    def update_remote
      raise "Not Implemented"
    end

    def synced?
      !!self.uri
    end

    def fetch
      if synced?
        "#{self.service_name}::#{remote_entity_type}".constantize.find(self.uri)
      end
    end

    def remote_entity_type
      "#{self.class.name.gsub("Transactionable::Remote","")}"
    end

    def destroy_remote
      re = self.fetch
      re.unstore if re
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
transactionable-0.3.1 app/models/transactionable/remote_entity.rb
transactionable-0.3.0 app/models/transactionable/remote_entity.rb
transactionable-0.2.0 app/models/transactionable/remote_entity.rb
transactionable-0.1.0 app/models/transactionable/remote_entity.rb