sync_machine 1.2.0 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 102155af0851cece6b27470411c50f11c945be750d08c6acb98093b011f65e85
4
- data.tar.gz: 956031cb81b308903a5606d43c877eed613f4c3a3302b655592f1ce891197357
3
+ metadata.gz: 582b683ceda765fc486ebbe449206c61ad2aceded9e1f0cdc68a023510f4ebbb
4
+ data.tar.gz: 4145f8fca67cca0a36dbde2b7302333d0f3da6c8aa56ef0bf00106b49f45f5b6
5
5
  SHA512:
6
- metadata.gz: 0e0718d0e199a23ca685eccd530cffa3bdd49969925536d2881fea680126aa96a83a8ebae0ea871e93179670928df40b4564962c02d10641bf2b92d6159f571a
7
- data.tar.gz: 52ac953901aed56ca103e58e7285fc15bb2acdec89a9ad9f88531b01e91d080aaed78892e9d835b6df6e55b7219c475681fd10708d79b1f94557b4a269ac633a
6
+ metadata.gz: 06cbe6d8e456c10ae14466501f7995be45f58b43dcf3b4b51c7cb1f0cbca1888d9eff76d12790ac17867ce551431734348cfdd6c728f44f1316d70482ded446a
7
+ data.tar.gz: c188d5bc1baa7c74dd9a4dc947ca8df7cdd41e823ac4577dd46265dc3607d2d79200b8f79985d44c1d9e1e0bf0eb565a507445f98ee99b52ac85eeadc121b064
data/.travis.yml CHANGED
@@ -2,6 +2,15 @@
2
2
  sudo: false
3
3
  language: ruby
4
4
  cache: bundler
5
+ gemfile:
6
+ - Gemfile.mongoid6-activesupport5
7
+ - Gemfile.mongoid7
5
8
  rvm:
6
9
  - 2.4.2
10
+ - 2.5.7
11
+ - 2.6.3
12
+ matrix:
13
+ exclude:
14
+ - gemfile: Gemfile.mongoid7
15
+ rvm: 2.4.2
7
16
  before_install: gem install bundler -v 2.0.1
@@ -0,0 +1,18 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Runtime dependencies
4
+ gem 'activesupport', '>= 5', '< 6'
5
+ gem 'mongoid', '>= 6', '< 7'
6
+
7
+ # Development dependencies
8
+ gem 'activerecord'
9
+ gem 'factory_bot'
10
+ gem 'fhwang-wisper-mongoid', '>= 0.3.0'
11
+ gem 'gemika'
12
+ gem 'opentracing'
13
+ gem 'rspec'
14
+ gem 'sqlite3'
15
+ gem 'wisper-activerecord'
16
+
17
+ # Gem under test
18
+ gem 'sync_machine', path: '.'
@@ -0,0 +1,92 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ sync_machine (1.2.0)
5
+ activesupport
6
+ sidekiq
7
+ wisper
8
+
9
+ GEM
10
+ remote: https://rubygems.org/
11
+ specs:
12
+ activemodel (5.2.3)
13
+ activesupport (= 5.2.3)
14
+ activerecord (5.2.3)
15
+ activemodel (= 5.2.3)
16
+ activesupport (= 5.2.3)
17
+ arel (>= 9.0)
18
+ activesupport (5.2.3)
19
+ concurrent-ruby (~> 1.0, >= 1.0.2)
20
+ i18n (>= 0.7, < 2)
21
+ minitest (~> 5.1)
22
+ tzinfo (~> 1.1)
23
+ arel (9.0.0)
24
+ bson (4.6.0)
25
+ concurrent-ruby (1.1.5)
26
+ connection_pool (2.2.2)
27
+ diff-lcs (1.3)
28
+ factory_bot (5.1.1)
29
+ activesupport (>= 4.2.0)
30
+ fhwang-wisper-mongoid (0.3.0)
31
+ activesupport
32
+ mongoid (>= 6)
33
+ wisper
34
+ gemika (0.4.0)
35
+ i18n (1.7.0)
36
+ concurrent-ruby (~> 1.0)
37
+ minitest (5.13.0)
38
+ mongo (2.11.1)
39
+ bson (>= 4.6.0, < 5.0.0)
40
+ mongoid (6.4.4)
41
+ activemodel (>= 5.1, < 6.0.0)
42
+ mongo (>= 2.5.1, < 3.0.0)
43
+ opentracing (0.5.0)
44
+ rack (2.0.7)
45
+ rack-protection (2.0.7)
46
+ rack
47
+ redis (4.1.3)
48
+ rspec (3.9.0)
49
+ rspec-core (~> 3.9.0)
50
+ rspec-expectations (~> 3.9.0)
51
+ rspec-mocks (~> 3.9.0)
52
+ rspec-core (3.9.0)
53
+ rspec-support (~> 3.9.0)
54
+ rspec-expectations (3.9.0)
55
+ diff-lcs (>= 1.2.0, < 2.0)
56
+ rspec-support (~> 3.9.0)
57
+ rspec-mocks (3.9.0)
58
+ diff-lcs (>= 1.2.0, < 2.0)
59
+ rspec-support (~> 3.9.0)
60
+ rspec-support (3.9.0)
61
+ sidekiq (5.2.7)
62
+ connection_pool (~> 2.2, >= 2.2.2)
63
+ rack (>= 1.5.0)
64
+ rack-protection (>= 1.5.0)
65
+ redis (>= 3.3.5, < 5)
66
+ sqlite3 (1.4.1)
67
+ thread_safe (0.3.6)
68
+ tzinfo (1.2.5)
69
+ thread_safe (~> 0.1)
70
+ wisper (2.0.1)
71
+ wisper-activerecord (1.0.0)
72
+ activerecord (>= 3.0.0)
73
+ wisper (~> 2.0)
74
+
75
+ PLATFORMS
76
+ ruby
77
+
78
+ DEPENDENCIES
79
+ activerecord
80
+ activesupport (>= 5, < 6)
81
+ factory_bot
82
+ fhwang-wisper-mongoid (>= 0.3.0)
83
+ gemika
84
+ mongoid (>= 6, < 7)
85
+ opentracing
86
+ rspec
87
+ sqlite3
88
+ sync_machine!
89
+ wisper-activerecord
90
+
91
+ BUNDLED WITH
92
+ 2.0.2
data/Gemfile.mongoid7 ADDED
@@ -0,0 +1,17 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Runtime dependencies
4
+ gem 'mongoid', '>= 7'
5
+
6
+ # Development dependencies
7
+ gem 'activerecord'
8
+ gem 'factory_bot'
9
+ gem 'fhwang-wisper-mongoid', '>= 0.3.0'
10
+ gem 'gemika'
11
+ gem 'opentracing'
12
+ gem 'rspec'
13
+ gem 'sqlite3'
14
+ gem 'wisper-activerecord'
15
+
16
+ # Gem under test
17
+ gem 'sync_machine', path: '.'
@@ -0,0 +1,91 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ sync_machine (1.2.0)
5
+ activesupport
6
+ sidekiq
7
+ wisper
8
+
9
+ GEM
10
+ remote: https://rubygems.org/
11
+ specs:
12
+ activemodel (6.0.1)
13
+ activesupport (= 6.0.1)
14
+ activerecord (6.0.1)
15
+ activemodel (= 6.0.1)
16
+ activesupport (= 6.0.1)
17
+ activesupport (6.0.1)
18
+ concurrent-ruby (~> 1.0, >= 1.0.2)
19
+ i18n (>= 0.7, < 2)
20
+ minitest (~> 5.1)
21
+ tzinfo (~> 1.1)
22
+ zeitwerk (~> 2.2)
23
+ bson (4.6.0)
24
+ concurrent-ruby (1.1.5)
25
+ connection_pool (2.2.2)
26
+ diff-lcs (1.3)
27
+ factory_bot (5.1.1)
28
+ activesupport (>= 4.2.0)
29
+ fhwang-wisper-mongoid (0.3.0)
30
+ activesupport
31
+ mongoid (>= 6)
32
+ wisper
33
+ gemika (0.4.0)
34
+ i18n (1.7.0)
35
+ concurrent-ruby (~> 1.0)
36
+ minitest (5.13.0)
37
+ mongo (2.11.1)
38
+ bson (>= 4.6.0, < 5.0.0)
39
+ mongoid (7.0.5)
40
+ activemodel (>= 5.1, < 6.1)
41
+ mongo (>= 2.5.1, < 3.0.0)
42
+ opentracing (0.5.0)
43
+ rack (2.0.7)
44
+ rack-protection (2.0.7)
45
+ rack
46
+ redis (4.1.3)
47
+ rspec (3.9.0)
48
+ rspec-core (~> 3.9.0)
49
+ rspec-expectations (~> 3.9.0)
50
+ rspec-mocks (~> 3.9.0)
51
+ rspec-core (3.9.0)
52
+ rspec-support (~> 3.9.0)
53
+ rspec-expectations (3.9.0)
54
+ diff-lcs (>= 1.2.0, < 2.0)
55
+ rspec-support (~> 3.9.0)
56
+ rspec-mocks (3.9.0)
57
+ diff-lcs (>= 1.2.0, < 2.0)
58
+ rspec-support (~> 3.9.0)
59
+ rspec-support (3.9.0)
60
+ sidekiq (6.0.3)
61
+ connection_pool (>= 2.2.2)
62
+ rack (>= 2.0.0)
63
+ rack-protection (>= 2.0.0)
64
+ redis (>= 4.1.0)
65
+ sqlite3 (1.4.1)
66
+ thread_safe (0.3.6)
67
+ tzinfo (1.2.5)
68
+ thread_safe (~> 0.1)
69
+ wisper (2.0.1)
70
+ wisper-activerecord (1.0.0)
71
+ activerecord (>= 3.0.0)
72
+ wisper (~> 2.0)
73
+ zeitwerk (2.2.1)
74
+
75
+ PLATFORMS
76
+ ruby
77
+
78
+ DEPENDENCIES
79
+ activerecord
80
+ factory_bot
81
+ fhwang-wisper-mongoid (>= 0.3.0)
82
+ gemika
83
+ mongoid (>= 7)
84
+ opentracing
85
+ rspec
86
+ sqlite3
87
+ sync_machine!
88
+ wisper-activerecord
89
+
90
+ BUNDLED WITH
91
+ 2.0.2
data/Rakefile CHANGED
@@ -1,6 +1,7 @@
1
1
  require "bundler/gem_tasks"
2
+ require "gemika/tasks"
2
3
  require "rspec/core/rake_task"
3
4
 
4
5
  RSpec::Core::RakeTask.new(:spec)
5
6
 
6
- task default: :spec
7
+ task default: 'matrix:spec'
@@ -3,6 +3,9 @@ module <%= class_name %>
3
3
  check_publishable do |<%= subject %>|
4
4
  # Return a boolean value indicating whether the <%= subject %>
5
5
  # should be published at all.
6
+ #
7
+ # This step is optional. If the step is deleted, the <%= subject %>
8
+ # is considered always publishable.
6
9
  end
7
10
 
8
11
  build do |<%= subject %>|
@@ -14,8 +17,9 @@ module <%= class_name %>
14
17
  end
15
18
 
16
19
  after_publish do |<%= subject %>|
17
- # Execute any actions after a successful publish. This step is optional
18
- # and can be deleted entirely.
20
+ # Execute any actions after a successful publish.
21
+ #
22
+ # This step is optional and can be deleted entirely.
19
23
  end
20
24
  end
21
25
  end
@@ -8,7 +8,15 @@ module SyncMachine
8
8
  # occurs.
9
9
  class ChangeListener
10
10
  def self.inherited(base)
11
- base.cattr_accessor :model_syms
11
+ base.cattr_accessor :model_syms do
12
+ []
13
+ end
14
+ end
15
+
16
+ def self.define_method_matching_wisper_event(event)
17
+ define_method(event) do |subject|
18
+ find_subjects_async(subject)
19
+ end
12
20
  end
13
21
 
14
22
  def self.listen_to_models(*model_syms)
@@ -22,6 +30,12 @@ module SyncMachine
22
30
  end
23
31
  end
24
32
 
33
+ def self.listen_to_wisper_events(*events)
34
+ events.each do |event|
35
+ define_method_matching_wisper_event(event)
36
+ end
37
+ end
38
+
25
39
  def self.subscribe
26
40
  Wisper.subscribe(new)
27
41
  end
@@ -34,24 +48,15 @@ module SyncMachine
34
48
 
35
49
  def after_record_saved(record)
36
50
  return unless orm_adapter.sufficient_changes_to_find_subjects?(record)
37
- sync_module = SyncMachine.sync_module(self.class)
38
- finder_class = sync_module.const_get('FindSubjectsWorker')
39
- finder_class.perform_async(
40
- record.class.name,
41
- record_id_for_job(record.id),
42
- changed_keys(record),
43
- Time.now.to_json
44
- )
51
+ find_subjects_async(record)
45
52
  end
46
53
 
47
54
  private
48
55
 
49
- def changed_keys(record)
50
- orm_adapter.change_listener_changed_keys(record)
51
- end
52
-
53
- def record_id_for_job(record_id)
54
- orm_adapter.record_id_for_job(record_id)
56
+ def find_subjects_async(record)
57
+ sync_module = SyncMachine.sync_module(self.class)
58
+ finder_class = sync_module.const_get('FindSubjectsWorker')
59
+ finder_class.perform_async_for_record(record)
55
60
  end
56
61
 
57
62
  def orm_adapter
@@ -47,8 +47,12 @@ module SyncMachine
47
47
  )
48
48
  end
49
49
 
50
+ def publishable?
51
+ !hook(:check_publishable) || hook(:check_publishable).call(@subject)
52
+ end
53
+
50
54
  def run_deduped
51
- return unless hook(:check_publishable).call(@subject)
55
+ return unless publishable?
52
56
  if publication_history.last_publish_equals?(payload_body)
53
57
  publication_history.record_generation_time
54
58
  else
@@ -30,6 +30,16 @@ module SyncMachine
30
30
  end
31
31
  end
32
32
 
33
+ def self.perform_async_for_record(record)
34
+ sync_module = SyncMachine.sync_module(self)
35
+ orm_adapter = sync_module.orm_adapter
36
+ record_id_for_job = orm_adapter.record_id_for_job(record.id)
37
+ changed_keys = orm_adapter.change_listener_changed_keys(record)
38
+ perform_async(
39
+ record.class.name, record_id_for_job, changed_keys, Time.now.to_json
40
+ )
41
+ end
42
+
33
43
  # :reek:LongParameterList is unavoidable here since this is a Sidekiq
34
44
  # worker
35
45
  def perform(record_class_name, record_id, changed_keys, enqueue_time_str)
@@ -1,3 +1,3 @@
1
1
  module SyncMachine
2
- VERSION = "1.2.0".freeze
2
+ VERSION = "1.3.0".freeze
3
3
  end
data/sync_machine.gemspec CHANGED
@@ -43,6 +43,7 @@ Gem::Specification.new do |spec|
43
43
  spec.add_development_dependency "bundler", "~> 2.0"
44
44
  spec.add_development_dependency "factory_bot"
45
45
  spec.add_development_dependency "fhwang-wisper-mongoid"
46
+ spec.add_development_dependency "gemika"
46
47
  spec.add_development_dependency "mongoid"
47
48
  spec.add_development_dependency "opentracing"
48
49
  spec.add_development_dependency "rake", "~> 10.0"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sync_machine
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Francis Hwang
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-11-26 00:00:00.000000000 Z
11
+ date: 2019-12-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -108,6 +108,20 @@ dependencies:
108
108
  - - ">="
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: gemika
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
111
125
  - !ruby/object:Gem::Dependency
112
126
  name: mongoid
113
127
  requirement: !ruby/object:Gem::Requirement
@@ -223,6 +237,10 @@ files:
223
237
  - ".travis.yml"
224
238
  - CODE_OF_CONDUCT.md
225
239
  - Gemfile
240
+ - Gemfile.mongoid6-activesupport5
241
+ - Gemfile.mongoid6-activesupport5.lock
242
+ - Gemfile.mongoid7
243
+ - Gemfile.mongoid7.lock
226
244
  - LICENSE.txt
227
245
  - README.md
228
246
  - Rakefile