Class: Synced::Strategies::SyncedPerScopeTimestampStrategy

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

Overview

This is a strategy for UpdatedSince defining how to store and update synced timestamps. It uses a separate timestamps table to track when different models were synced in specific scopes.

Instance Method Summary collapse

Constructor Details

#initialize(scope: nil, model_class:, **_options) ⇒ SyncedPerScopeTimestampStrategy

Returns a new instance of SyncedPerScopeTimestampStrategy.



11
12
13
14
# File 'lib/synced/strategies/synced_per_scope_timestamp_strategy.rb', line 11

def initialize(scope: nil, model_class:, **_options)
  @scope = scope
  @model_class = model_class
end

Instance Method Details

#last_synced_atObject



16
17
18
# File 'lib/synced/strategies/synced_per_scope_timestamp_strategy.rb', line 16

def last_synced_at
  timestamp_repository.last_synced_at
end

#resetObject



24
25
26
# File 'lib/synced/strategies/synced_per_scope_timestamp_strategy.rb', line 24

def reset
  timestamp_repository.delete_all
end

#update(timestamp) ⇒ Object



20
21
22
# File 'lib/synced/strategies/synced_per_scope_timestamp_strategy.rb', line 20

def update(timestamp)
  timestamp_repository.create!(synced_at: timestamp)
end