Class: WatermelonDbSync::SyncPull

Inherits:
Sync
  • Object
show all
Defined in:
lib/watermelon_db_sync/sync_pull.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Sync

last_global_seqs, next_global_seqs

Constructor Details

#initialize(params) ⇒ SyncPull

Returns a new instance of SyncPull.



5
6
7
8
9
10
# File 'lib/watermelon_db_sync/sync_pull.rb', line 5

def initialize(params)
  @last_pulled_version = params[:last_pulled_version].to_i || 0
  @push_id = params[:push_id]
  @models = WatermelonDbSync.configuration.sync_models
  @data = { last_global_seqs: 0, response: build_default_response }
end

Instance Attribute Details

#dataObject

Returns the value of attribute data.



3
4
5
# File 'lib/watermelon_db_sync/sync_pull.rb', line 3

def data
  @data
end

#last_pulled_versionObject

Returns the value of attribute last_pulled_version.



3
4
5
# File 'lib/watermelon_db_sync/sync_pull.rb', line 3

def last_pulled_version
  @last_pulled_version
end

#modelsObject

Returns the value of attribute models.



3
4
5
# File 'lib/watermelon_db_sync/sync_pull.rb', line 3

def models
  @models
end

Instance Method Details

#get_from_allObject



16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/watermelon_db_sync/sync_pull.rb', line 16

def get_from_all
  max_versions = @models.map do |model_name|
    model = model_name.constantize
    query(model)
  end

  @data[:last_global_seqs] =
    max_versions.flatten.compact.max || @last_pulled_version

  true
rescue => e
  e.message
end

#pullObject



12
13
14
# File 'lib/watermelon_db_sync/sync_pull.rb', line 12

def pull
  get_from_all
end