syncable_models 0.0.15 → 0.0.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- YjUzZGRmMTQ5MDNhMTAxZDkwOGY4NDUyN2YwOTIxMmE3NTE5ZmJlZQ==
4
+ OGE2MWUwMmExODFiYmNiNTE4NTIxN2NkOTJkNzdlZWVmMjAyYjJjMQ==
5
5
  data.tar.gz: !binary |-
6
- MzQwMTNmZTUzYzBmOThkNzQ4ZDcyMDI3NzZiNWU5MDg3MTk0ZGNlNw==
6
+ MTY2Y2Y5ZWFjZDcwYjkxZWM2Y2JmZjc2MWEwMzEzNTExNWFiMWIzOQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- MDdjMjExYjg5YWJlMGE0NGE5Y2Y0MzVhOWEwYjcyOTkzMzYxZDUyOTZiNmE5
10
- YzgxYWJmY2EyYzlmMTM1MjdhMGJiM2ZiZjlmNzlkMzExZThmMDExNWUxNDE5
11
- NTM1ODgzMzQzNGI4NDA5MjA2MjNhY2QxNjVkNDQyNDVlZmM1M2E=
9
+ ZTEyMDAyZDAxNjM1M2Q5MWI3OTY1MTMxYjg5YWZhZWMyNWM4YjI5YTZkZTg2
10
+ OWE2ZTM5ZWIzZTM1NGFkMTY2MzE5ZmU5OTg0MjU0YjY3OTQ2YTI2NzQ5ODFj
11
+ MzU4MDViNzMxMWM2ZGIwZDQ4NDU2NmFlZTQyNzI3NmZlN2NmOTc=
12
12
  data.tar.gz: !binary |-
13
- NTc0N2E3OGQzNjhjN2I0YjZjYWEzMzk0NGQyNWM5ZDUyZmVhZGM5NGU0OWRk
14
- MTkyYWNlODU1OGY0OWQyMmYzOGM1Mzg3NzE4ZDA2NTdlNDNmMWExZDBkZThh
15
- MGI3ZDg3Y2EzZDY2NDkyYjk1OGVjNDQ3Mzk1MWY1MmQ4OTNlZjM=
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.not_synced(params[:destination]).limit(count).map(&:to_import_hash)
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
@@ -1,3 +1,3 @@
1
1
  module SyncableModels
2
- VERSION = "0.0.15"
2
+ VERSION = "0.0.16"
3
3
  end
@@ -1,5 +1,5 @@
1
1
  class Project < ActiveRecord::Base
2
- syncable scope: :not_deleted
2
+ syncable scope: :not_deleted, conditions: { condition_test: ->(){ where.not(name: 'TestProject') } }
3
3
 
4
4
  validates :name, :uuid, presence: true
5
5