Module: SyncableModels::ActiveRecord
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/syncable_models/active_record.rb
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
- #clear_syncs(destination = nil) ⇒ Object
- #clear_syncs_on_update ⇒ Object
- #set_syncs_destroyed ⇒ Object
- #sync(destination) ⇒ Object
- #syncable_models_external_id ⇒ Object
- #synced?(destination) ⇒ Boolean
- #to_import_hash ⇒ Object
Instance Method Details
#clear_syncs(destination = nil) ⇒ Object
34 35 36 |
# File 'lib/syncable_models/active_record.rb', line 34 def clear_syncs(destination = nil) (destination ? syncs.by_destination(destination) : syncs).destroy_all end |
#clear_syncs_on_update ⇒ Object
42 43 44 |
# File 'lib/syncable_models/active_record.rb', line 42 def clear_syncs_on_update clear_syncs end |
#set_syncs_destroyed ⇒ Object
46 47 48 49 |
# File 'lib/syncable_models/active_record.rb', line 46 def set_syncs_destroyed SyncableModels::Sync.where(subject_external_id: self.syncable_models_external_id) .update_all(subject_destroyed: true) end |
#sync(destination) ⇒ Object
30 31 32 |
# File 'lib/syncable_models/active_record.rb', line 30 def sync(destination) syncs.create(destination: destination) unless synced?(destination) end |
#syncable_models_external_id ⇒ Object
38 39 40 |
# File 'lib/syncable_models/active_record.rb', line 38 def syncable_models_external_id self.send(self.class.syncable_models_id_key) end |
#synced?(destination) ⇒ Boolean
26 27 28 |
# File 'lib/syncable_models/active_record.rb', line 26 def synced?(destination) syncs.where(destination: destination).exists? end |
#to_import_hash ⇒ Object
51 52 53 |
# File 'lib/syncable_models/active_record.rb', line 51 def to_import_hash attributes end |