Module: Equipoise::Syncable
- Defined in:
- lib/equipoise/syncable.rb
Class Method Summary collapse
Instance Method Summary collapse
- #deactivate_from_equipoise ⇒ Object
-
#equipoise_contact_attributes ⇒ Object
Host models MUST implement this — the attributes posted on each sync.
-
#equipoise_external_id ⇒ Object
— Sensible default; override in the host model when the external id isn't the primary key.
-
#equipoise_sync! ⇒ Object
Override to enqueue instead of posting inline.
- #sync_to_equipoise ⇒ Object
Class Method Details
.included(base) ⇒ Object
37 38 39 40 41 |
# File 'lib/equipoise/syncable.rb', line 37 def self.included(base) return unless base.respond_to?(:after_commit) base.after_commit :equipoise_sync!, on: [:create, :update] end |
Instance Method Details
#deactivate_from_equipoise ⇒ Object
63 64 65 |
# File 'lib/equipoise/syncable.rb', line 63 def deactivate_from_equipoise Equipoise.client.contacts.deactivate(external_id: equipoise_external_id) end |
#equipoise_contact_attributes ⇒ Object
Host models MUST implement this — the attributes posted on each sync.
74 75 76 |
# File 'lib/equipoise/syncable.rb', line 74 def equipoise_contact_attributes raise NotImplementedError, "#{self.class} must define #equipoise_contact_attributes" end |
#equipoise_external_id ⇒ Object
— Sensible default; override in the host model when the external id isn't the primary key.
69 70 71 |
# File 'lib/equipoise/syncable.rb', line 69 def equipoise_external_id id.to_s end |
#equipoise_sync! ⇒ Object
Override to enqueue instead of posting inline. No-op until configured so a
boot before credentials exist (or a test env) doesn't make live calls.
Rescues Equipoise::Error so a transient API/transport failure in this
after_commit hook never propagates out of the host's save! (Rails 7.1+
re-raises after_commit exceptions). Best-effort, like envelope tracking.
Host bugs (a NoMethodError in equipoise_contact_attributes) still surface.
49 50 51 52 53 54 55 56 57 |
# File 'lib/equipoise/syncable.rb', line 49 def equipoise_sync! return unless Equipoise.configured? sync_to_equipoise rescue Equipoise::Error => e Equipoise.configuration.logger&.warn( "[equipoise] sync failed for #{self.class}##{equipoise_external_id}: #{e.}" ) end |