Module: Synced::Engine::Model
- Defined in:
- lib/synced/engine/model.rb
Instance Method Summary collapse
-
#synced(options = {}) ⇒ Object
Enables synced for ActiveRecord model.
-
#synchronize(remote: nil, model_class: self, scope: nil, remove: false) ⇒ Object
Performs synchronization of given remote objects to local database.
Instance Method Details
#synced(options = {}) ⇒ Object
Enables synced for ActiveRecord model.
20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/synced/engine/model.rb', line 20 def synced( = {}) class_attribute :synced_id_key, :synced_all_at_key, :synced_data_key, :synced_local_attributes, :synced_associations, :synced_only_updated self.synced_id_key = .fetch(:id_key, :synced_id) self.synced_all_at_key = .fetch(:synced_all_at_key, :synced_all_at) self.synced_data_key = .fetch(:data_key, :synced_data) self.synced_local_attributes = .fetch(:local_attributes, []) self.synced_associations = .fetch(:associations, []) self.synced_only_updated = .fetch(:only_updated, false) include Synced::Engine::HasSyncedData end |
#synchronize(remote: nil, model_class: self, scope: nil, remove: false) ⇒ Object
Performs synchronization of given remote objects to local database.
Rental.synchronize(remote: remote_rentals, scope: website)
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/synced/engine/model.rb', line 59 def synchronize(remote: nil, model_class: self, scope: nil, remove: false) = { scope: scope, id_key: synced_id_key, synced_all_at_key: synced_all_at_key, data_key: synced_data_key, remove: remove, local_attributes: synced_local_attributes, associations: synced_associations, only_updated: synced_only_updated } synchronizer = Synced::Engine::Synchronizer.new(remote, model_class, ) synchronizer.perform end |