Class: Synchronisable::Synchronizer Abstract
- Includes:
- DSL::Associations, DSL::Macro
- Defined in:
- lib/synchronisable/synchronizer.rb
Overview
Subclass to create your model specific synchronizer class to setup synchronization attributes and behavior.
Direct Known Subclasses
Constant Summary collapse
- SYMBOL_ARRAY_CONVERTER =
->(source) { ([*source] || []).map(&:to_s) }
Class Method Summary collapse
-
.extract_remote_id(attrs) ⇒ Object
private
Extracts remote id from given attribute hash.
- .fetch(params = {}) ⇒ Object
- .find(params) ⇒ Object
-
.map_attributes(attrs) ⇒ Hash
private
Maps the remote attributes to local model attributes.
- .uid(attrs) ⇒ Object
Instance Method Summary collapse
-
#before_association_sync ⇒ Boolean
Lambda, that will be called before each association sync.
-
#before_record_sync ⇒ Boolean
Lambda, that will be called before synchronization of each record.
-
#before_sync ⇒ Boolean
Lambda, that will be called before synchronization of each record and its assocations.
Class Method Details
.extract_remote_id(attrs) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Extracts remote id from given attribute hash.
141 142 143 144 |
# File 'lib/synchronisable/synchronizer.rb', line 141 def extract_remote_id(attrs) id = attrs.delete(remote_id) ensure_remote_id(id) end |
.fetch(params = {}) ⇒ Object
118 119 120 121 |
# File 'lib/synchronisable/synchronizer.rb', line 118 def fetch(params = {}) data = fetcher.(params) data.present? ? data : gateway_instance.try(:fetch, params) end |
.find(params) ⇒ Object
123 124 125 126 |
# File 'lib/synchronisable/synchronizer.rb', line 123 def find(params) data = finder.(params) data.present? ? data : gateway_instance.try(:find, params) end |
.map_attributes(attrs) ⇒ Hash
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Maps the remote attributes to local model attributes.
152 153 154 155 156 157 158 |
# File 'lib/synchronisable/synchronizer.rb', line 152 def map_attributes(attrs) AttributeMapper.map(attrs, mappings, { :only => only, :except => except, :keep => associations.keys }) end |
.uid(attrs) ⇒ Object
128 129 130 |
# File 'lib/synchronisable/synchronizer.rb', line 128 def uid(attrs) unique_id.is_a?(Proc) ? unique_id.(attrs) : attrs[unique_id] end |
Instance Method Details
#before_association_sync ⇒ Boolean
Lambda, that will be called before each association sync.
107 |
# File 'lib/synchronisable/synchronizer.rb', line 107 method :before_association_sync |
#before_record_sync ⇒ Boolean
Lambda, that will be called before synchronization of each record.
92 |
# File 'lib/synchronisable/synchronizer.rb', line 92 method :before_record_sync |
#before_sync ⇒ Boolean
Lambda, that will be called before synchronization of each record and its assocations.
80 |
# File 'lib/synchronisable/synchronizer.rb', line 80 method :before_sync |