syncable_models 0.0.15 → 0.0.16
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/lib/syncable_models/controller.rb +4 -1
- data/lib/syncable_models/syncable.rb +11 -3
- data/lib/syncable_models/version.rb +1 -1
- data/spec/dummy/app/models/project.rb +1 -1
- data/spec/dummy/log/test.log +457 -422
- data/spec/models/syncable_models/syncable_spec.rb +28 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
OGE2MWUwMmExODFiYmNiNTE4NTIxN2NkOTJkNzdlZWVmMjAyYjJjMQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
MTY2Y2Y5ZWFjZDcwYjkxZWM2Y2JmZjc2MWEwMzEzNTExNWFiMWIzOQ==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
ZTEyMDAyZDAxNjM1M2Q5MWI3OTY1MTMxYjg5YWZhZWMyNWM4YjI5YTZkZTg2
|
10
|
+
OWE2ZTM5ZWIzZTM1NGFkMTY2MzE5ZmU5OTg0MjU0YjY3OTQ2YTI2NzQ5ODFj
|
11
|
+
MzU4MDViNzMxMWM2ZGIwZDQ4NDU2NmFlZTQyNzI3NmZlN2NmOTc=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
YmNhMmQ2YWNkN2QyMTkwN2FmY2QzN2ZmYTgzYzU4NjMxYzdlMDI2ODU1ODIy
|
14
|
+
MzFmMGM4YzRhODI2MjUxNmZiOTU0N2RjNzdmOWY4MjE5ZjAyNzYxYmZjM2Nj
|
15
|
+
MTllNTE1ZWE3OTYzYTE4NGIxOGZkYmNkYmY0NjU4NWM3ZmVmNTY=
|
@@ -32,7 +32,10 @@ module SyncableModels::Controller
|
|
32
32
|
if params[:destination]
|
33
33
|
count = params[:count].present? ? params[:count].to_i : BATCH_COUNT
|
34
34
|
|
35
|
-
for_sync = klass.syncable_models_suitable
|
35
|
+
for_sync = klass.syncable_models_suitable(params[:destination])
|
36
|
+
.not_synced(params[:destination])
|
37
|
+
.limit(count)
|
38
|
+
.map(&:to_import_hash)
|
36
39
|
count = count - for_sync.count
|
37
40
|
|
38
41
|
for_destroy = SyncableModels::Sync
|
@@ -3,19 +3,27 @@ require 'active_support'
|
|
3
3
|
module SyncableModels
|
4
4
|
module Syncable
|
5
5
|
def syncable(options = {})
|
6
|
-
options.assert_valid_keys(:id_key, :scope)
|
6
|
+
options.assert_valid_keys(:id_key, :scope, :conditions)
|
7
7
|
|
8
8
|
class_attribute :syncable_models_id_key
|
9
9
|
class_attribute :syncable_models_scope
|
10
|
+
class_attribute :syncable_models_conditions
|
10
11
|
|
11
12
|
self.syncable_models_id_key = options[:id_key] || :uuid
|
12
13
|
self.syncable_models_scope = options[:scope] || nil
|
14
|
+
self.syncable_models_conditions = options[:conditions] || {}
|
13
15
|
|
14
16
|
include SyncableModels::ActiveRecord
|
15
17
|
end
|
16
18
|
|
17
|
-
def syncable_models_suitable
|
18
|
-
syncable_models_scope? ? self.send(syncable_models_scope) : self
|
19
|
+
def syncable_models_suitable(destination)
|
20
|
+
result = syncable_models_scope? ? self.send(syncable_models_scope) : self
|
21
|
+
|
22
|
+
if syncable_models_conditions[destination].present?
|
23
|
+
result = syncable_models_conditions[destination].call
|
24
|
+
end
|
25
|
+
|
26
|
+
result
|
19
27
|
end
|
20
28
|
end
|
21
29
|
end
|