Module: Synced::Model
- Defined in:
- lib/synced/model.rb
Instance Method Summary collapse
-
#reset_synced ⇒ Object
Reset synced_all_at for given scope, this forces synced to sync all the records on the next sync.
-
#synced(options = {}) ⇒ Object
Enables synced for ActiveRecord model.
-
#synchronize(options = {}) ⇒ Object
Performs synchronization of given remote objects to local database.
Instance Method Details
#reset_synced ⇒ Object
Reset synced_all_at for given scope, this forces synced to sync all the records on the next sync. Useful for cases when you add a new column to be synced and you use updated since strategy for faster synchronization.
107 108 109 110 |
# File 'lib/synced/model.rb', line 107 def reset_synced return unless synced_only_updated update_all(synced_all_at_key => nil) end |
#synced(options = {}) ⇒ Object
Enables synced for ActiveRecord model.
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/synced/model.rb', line 30 def synced( = {}) .symbolize_keys! .assert_valid_keys(:associations, :data_key, :fields, :id_key, :include, :local_attributes, :mapper, :only_updated, :remove, :synced_all_at_key) class_attribute :synced_id_key, :synced_all_at_key, :synced_data_key, :synced_local_attributes, :synced_associations, :synced_only_updated, :synced_mapper, :synced_remove, :synced_include, :synced_fields self.synced_id_key = .fetch(:id_key, :synced_id) self.synced_all_at_key = .fetch(:synced_all_at_key, synced_column_presence(:synced_all_at)) self.synced_data_key = .fetch(:data_key, synced_column_presence(:synced_data)) self.synced_local_attributes = .fetch(:local_attributes, []) self.synced_associations = .fetch(:associations, []) self.synced_only_updated = .fetch(:only_updated, column_names.include?(synced_all_at_key.to_s)) self.synced_mapper = .fetch(:mapper, nil) self.synced_remove = .fetch(:remove, false) self.synced_include = .fetch(:include, []) self.synced_fields = .fetch(:fields, []) include Synced::HasSyncedData end |
#synchronize(options = {}) ⇒ Object
Performs synchronization of given remote objects to local database.
Rental.synchronize(remote: remote_rentals, scope: website)
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/synced/model.rb', line 83 def synchronize( = {}) .symbolize_keys! .assert_valid_keys(:api, :fields, :include, :remote, :remove, :scope) [:remove] = synced_remove unless .has_key?(:remove) [:include] = Array(synced_include) unless .has_key?(:include) [:fields] = Array(synced_fields) unless .has_key?(:fields) .merge!({ id_key: synced_id_key, synced_data_key: synced_data_key, synced_all_at_key: synced_all_at_key, data_key: synced_data_key, local_attributes: synced_local_attributes, associations: synced_associations, only_updated: synced_only_updated, mapper: synced_mapper }) Synced::Synchronizer.new(self, ).perform end |