Class: Synchronisable::Synchronizer Abstract

Inherits:
Object
  • Object
show all
Includes:
DSL::Associations, DSL::Macro
Defined in:
lib/synchronisable/synchronizer.rb

Overview

This class is abstract.

Subclass to create your model specific synchronizer class to setup synchronization attributes and behavior.

Direct Known Subclasses

SynchronizerDefault

Constant Summary collapse

SYMBOL_ARRAY_CONVERTER =
->(source) { (source || []).map(&:to_s) }

Class Method Summary collapse

Instance Method Summary collapse

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.

Parameters:

  • attrs (Hash)

    remote attributes

Returns:

  • remote id value

Raises:

See Also:

  • #ensure_remote_id


122
123
124
125
# File 'lib/synchronisable/synchronizer.rb', line 122

def extract_remote_id(attrs)
  id = attrs.delete(remote_id)
  ensure_remote_id(id)
end

.fetchObject



103
104
105
106
# File 'lib/synchronisable/synchronizer.rb', line 103

def fetch
  data = fetcher.()
  data.present? ? data : gateway_instance.try(:fetch)
end

.find(id) ⇒ Object



108
109
110
111
# File 'lib/synchronisable/synchronizer.rb', line 108

def find(id)
  data = finder.(id)
  data.present? ? data : gateway_instance.try(:find, id)
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.

Parameters:

  • attrs (Hash)

    remote attributes

Returns:

  • (Hash)

    local mapped attributes



133
134
135
136
137
138
139
# File 'lib/synchronisable/synchronizer.rb', line 133

def map_attributes(attrs)
  AttributeMapper.map(attrs, mappings, {
    :only   => only,
    :except => except,
    :keep   => associations.keys
  })
end

Instance Method Details

#before_association_syncBoolean

Lambda, that will be called before each association sync.

Parameters:

Returns:

  • (Boolean)

    ‘true` to continue sync, `false` to cancel



92
# File 'lib/synchronisable/synchronizer.rb', line 92

method :before_association_sync

#before_record_syncBoolean

Lambda, that will be called before synchronization of each record.

Parameters:

Returns:

  • (Boolean)

    ‘true` to continue sync, `false` to cancel



77
# File 'lib/synchronisable/synchronizer.rb', line 77

method :before_record_sync

#before_syncBoolean

Lambda, that will be called before synchronization of each record and its assocations.

Parameters:

Returns:

  • (Boolean)

    ‘true` to continue sync, `false` to cancel



65
# File 'lib/synchronisable/synchronizer.rb', line 65

method :before_sync