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.
113 114 115 116 |
# File 'lib/synced/model.rb', line 113 def reset_synced return unless synced_only_updated update_all(synced_all_at_key => nil) end |
#synced(options = {}) ⇒ Object
Enables synced for ActiveRecord model.
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/synced/model.rb', line 32 def synced( = {}) .symbolize_keys! .assert_valid_keys(:associations, :data_key, :fields, :globalized_attributes, :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, :synced_globalized_attributes 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, []) self.synced_globalized_attributes = .fetch(:globalized_attributes, []) include Synced::HasSyncedData end |
#synchronize(options = {}) ⇒ Object
Performs synchronization of given remote objects to local database.
Rental.synchronize(remote: remote_rentals, scope: website)
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/synced/model.rb', line 88 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, globalized_attributes: synced_globalized_attributes }) Synced::Synchronizer.new(self, ).perform end |