class Synced::Strategies::SyncedPerScopeTimestampStrategy

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.

Attributes

model_class[R]
scope[R]

Public Class Methods

new(scope: nil, model_class:, **_options) click to toggle source
# 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

Public Instance Methods

last_synced_at() click to toggle source
# File lib/synced/strategies/synced_per_scope_timestamp_strategy.rb, line 16
def last_synced_at
  timestamp_repository.last_synced_at
end
reset() click to toggle source
# File lib/synced/strategies/synced_per_scope_timestamp_strategy.rb, line 24
def reset
  timestamp_repository.delete_all
end
update(timestamp) click to toggle source
# File lib/synced/strategies/synced_per_scope_timestamp_strategy.rb, line 20
def update(timestamp)
  timestamp_repository.create!(synced_at: timestamp)
end

Private Instance Methods

timestamp_repository() click to toggle source
# File lib/synced/strategies/synced_per_scope_timestamp_strategy.rb, line 30
def timestamp_repository
  @timestamp_repository ||= begin
    if scope
      Synced::Timestamp.with_scope_and_model(scope, model_class)
    else
      Synced::Timestamp.with_model(model_class)
    end
  end
end