synced 1.0.4 → 1.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/synced/model.rb +10 -4
- data/lib/synced/synchronizer.rb +19 -5
- data/lib/synced/version.rb +1 -1
- metadata +2 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bcd4edd03dc87fc6cd5cd837340cb752a417c4ff
|
4
|
+
data.tar.gz: d99b69c0ef5dbc59ac1ba882e4615e0079e46456
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 581410ff985c089f7e2a7de047f8b6d5b229330cefc7d84d3b63d5817c3c48b5df64820e486048125780c49df7b51e11509027ea452b368b75865ba9cd7b1e2a
|
7
|
+
data.tar.gz: 738dc68aae7c8f6aee54ed15b340345b48c96ee461ecb077a837a606d839591f09928bd4422df79403d7e28133d636bc278bb8d8b59d4ad67b3868473f292d31
|
data/lib/synced/model.rb
CHANGED
@@ -29,15 +29,18 @@ module Synced
|
|
29
29
|
# to remove: :mark_as_missing.
|
30
30
|
# @option options [Array|Hash] globalized_attributes: A list of attributes
|
31
31
|
# which will be mapped with their translations.
|
32
|
+
# @option options [Time|Proc] initial_sync_since: A point in time from which
|
33
|
+
# objects will be synchronized on first synchronization.
|
34
|
+
# Works only for partial (updated_since param) synchronizations.
|
32
35
|
def synced(options = {})
|
33
36
|
options.symbolize_keys!
|
34
37
|
options.assert_valid_keys(:associations, :data_key, :fields,
|
35
|
-
:globalized_attributes, :id_key, :include, :
|
36
|
-
:only_updated, :remove, :synced_all_at_key)
|
38
|
+
:globalized_attributes, :id_key, :include, :initial_sync_since,
|
39
|
+
:local_attributes, :mapper, :only_updated, :remove, :synced_all_at_key)
|
37
40
|
class_attribute :synced_id_key, :synced_all_at_key, :synced_data_key,
|
38
41
|
:synced_local_attributes, :synced_associations, :synced_only_updated,
|
39
42
|
:synced_mapper, :synced_remove, :synced_include, :synced_fields,
|
40
|
-
:synced_globalized_attributes
|
43
|
+
:synced_globalized_attributes, :synced_initial_sync_since
|
41
44
|
self.synced_id_key = options.fetch(:id_key, :synced_id)
|
42
45
|
self.synced_all_at_key = options.fetch(:synced_all_at_key,
|
43
46
|
synced_column_presence(:synced_all_at))
|
@@ -53,6 +56,8 @@ module Synced
|
|
53
56
|
self.synced_fields = options.fetch(:fields, [])
|
54
57
|
self.synced_globalized_attributes = options.fetch(:globalized_attributes,
|
55
58
|
[])
|
59
|
+
self.synced_initial_sync_since = options.fetch(:initial_sync_since,
|
60
|
+
nil)
|
56
61
|
include Synced::HasSyncedData
|
57
62
|
end
|
58
63
|
|
@@ -101,7 +106,8 @@ module Synced
|
|
101
106
|
associations: synced_associations,
|
102
107
|
only_updated: synced_only_updated,
|
103
108
|
mapper: synced_mapper,
|
104
|
-
globalized_attributes: synced_globalized_attributes
|
109
|
+
globalized_attributes: synced_globalized_attributes,
|
110
|
+
initial_sync_since: synced_initial_sync_since
|
105
111
|
})
|
106
112
|
Synced::Synchronizer.new(self, options).perform
|
107
113
|
end
|
data/lib/synced/synchronizer.rb
CHANGED
@@ -39,6 +39,9 @@ module Synced
|
|
39
39
|
# mapping remote objects attributes into local object attributes
|
40
40
|
# @option options [Array|Hash] globalized_attributes: A list of attributes
|
41
41
|
# which will be mapped with their translations.
|
42
|
+
# @option options [Time|Proc] initial_sync_since: A point in time from which
|
43
|
+
# objects will be synchronized on first synchronization.
|
44
|
+
# Works only for partial (updated_since param) synchronizations.
|
42
45
|
def initialize(model_class, options = {})
|
43
46
|
@model_class = model_class
|
44
47
|
@scope = options[:scope]
|
@@ -58,6 +61,7 @@ module Synced
|
|
58
61
|
@remote_objects = Array(options[:remote]) unless options[:remote].nil?
|
59
62
|
@request_performed = false
|
60
63
|
@globalized_attributes = attributes_as_hash(options[:globalized_attributes])
|
64
|
+
@initial_sync_since = options[:initial_sync_since]
|
61
65
|
end
|
62
66
|
|
63
67
|
def perform
|
@@ -185,14 +189,24 @@ module Synced
|
|
185
189
|
options[:include] += @include
|
186
190
|
end
|
187
191
|
options[:fields] = @fields if @fields.present?
|
188
|
-
options[:updated_since] =
|
192
|
+
options[:updated_since] = updated_since if updated_since_enabled?
|
189
193
|
options[:auto_paginate] = true
|
190
194
|
end
|
191
195
|
end
|
192
196
|
|
193
|
-
def
|
194
|
-
instrument("
|
195
|
-
relation_scope.minimum(@synced_all_at_key)
|
197
|
+
def updated_since
|
198
|
+
instrument("updated_since.synced") do
|
199
|
+
[relation_scope.minimum(@synced_all_at_key),
|
200
|
+
initial_sync_since].compact.min
|
201
|
+
end
|
202
|
+
end
|
203
|
+
|
204
|
+
def initial_sync_since
|
205
|
+
if @initial_sync_since.respond_to?(:call)
|
206
|
+
@initial_sync_since.arity == 0 ? @initial_sync_since.call :
|
207
|
+
@initial_sync_since.call(@scope)
|
208
|
+
else
|
209
|
+
@initial_sync_since
|
196
210
|
end
|
197
211
|
end
|
198
212
|
|
@@ -217,7 +231,7 @@ module Synced
|
|
217
231
|
end
|
218
232
|
|
219
233
|
def remove_relation
|
220
|
-
if @only_updated
|
234
|
+
if @only_updated && @request_performed
|
221
235
|
relation_scope.where(id_key => deleted_remote_objects_ids)
|
222
236
|
else
|
223
237
|
relation_scope.where.not(id_key => remote_objects_ids)
|
data/lib/synced/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: synced
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sebastien Grosjean
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-
|
12
|
+
date: 2014-10-28 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -192,4 +192,3 @@ signing_key:
|
|
192
192
|
specification_version: 4
|
193
193
|
summary: Keep your BookingSync Application synced with BookingSync.
|
194
194
|
test_files: []
|
195
|
-
has_rdoc:
|