Class: Synced::Strategies::UpdatedSince

Inherits:
Full
  • Object
show all
Defined in:
lib/synced/strategies/updated_since.rb

Overview

This strategy performs partial synchronization. It fetches only changes (additions, modifications and deletions) from the API.

Defined Under Namespace

Classes: CannotDeleteDueToNoDeletedIdsError, MissingTimestampError

Instance Method Summary collapse

Methods included from AttributesAsHash

#synced_attributes_as_hash

Constructor Details

#initialize(model_class, options = {}) ⇒ UpdatedSince

Returns a new instance of UpdatedSince.

Parameters:

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • initial_sync_since: (Time|Proc)

    A point in time from which objects will be synchronized on first synchronization.



11
12
13
14
15
16
17
# File 'lib/synced/strategies/updated_since.rb', line 11

def initialize(model_class, options = {})
  super
  @initial_sync_since = options[:initial_sync_since]
  @tolerance = options[:tolerance]
  timestampt_strategy_class = options[:timestamp_strategy] || Synced::Strategies::SyncedAllAtTimestampStrategy
  @timestamp_strategy = timestampt_strategy_class.new(relation_scope: relation_scope, scope: @scope, model_class: model_class)
end

Instance Method Details

#performObject



19
20
21
22
23
24
25
# File 'lib/synced/strategies/updated_since.rb', line 19

def perform
  super.tap do |local_objects|
    instrument("update_synced_timestamp_perform.synced", model: @model_class) do
      @timestamp_strategy.update(first_request_timestamp)
    end
  end
end

#reset_syncedObject



27
28
29
# File 'lib/synced/strategies/updated_since.rb', line 27

def reset_synced
  @timestamp_strategy.reset
end