Module: SyncableModels::ActiveRecord

Extended by:
ActiveSupport::Concern
Defined in:
lib/syncable_models/active_record.rb

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

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_updateObject



42
43
44
# File 'lib/syncable_models/active_record.rb', line 42

def clear_syncs_on_update
  clear_syncs
end

#set_syncs_destroyedObject



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_idObject



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

Returns:

  • (Boolean)


26
27
28
# File 'lib/syncable_models/active_record.rb', line 26

def synced?(destination)
  syncs.where(destination: destination).exists?
end

#to_import_hashObject



51
52
53
# File 'lib/syncable_models/active_record.rb', line 51

def to_import_hash
  attributes
end