table_sync 4.2.2 → 5.0.0

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,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1d5af530003a4144653d1866fda0a581a5ecf021cbcd8e7c2a29028c0e838eb2
4
- data.tar.gz: 836de51df89dc99294bd8be65eeaf4e00cba6bdb22071170bef42372c4984a70
3
+ metadata.gz: d78fecdf8f43cfa8a84fb4ce366af5c9a8da236988b66887ef5aff16c40e3f89
4
+ data.tar.gz: 47ad42e41cc6b3383977aa63105a8dc7c575115dddd00f868acfb6b4a15f73b5
5
5
  SHA512:
6
- metadata.gz: 2558335ef49a853d8d0d12878cdb42cfb91d4bf7dc7838f22c4853dbf09a22aa60569c420eaee0f5a667f21ea55c02b4a62d3c9d7a4299128d2a6d4b47d7b76a
7
- data.tar.gz: d24f3e8e2cab9f946a37296261d531a44b3ea6e660aa1a9424e0685c9ba2ffff73130e6b9661f3ff76a0636eab9c877e4f7b18ce2c1b7b65326bfb5d2434df48
6
+ metadata.gz: 17b77342ca100235816dbc5d1dabf9391eb0a612eb5c540776b6e7f234f23da4a50fe802a62e511e4148657f804a6e04159560798f650dfd3fb1c3b8f07cb005
7
+ data.tar.gz: 83e53da6b5895ee392a7b0d53e70509ce453c7973a0f08d3b8bd1b7cea7dc50d252a1848506206cbcfef80fa80bc16abea3f1f711ce4806097a540fac31e0bc3
@@ -0,0 +1,52 @@
1
+ name: CI
2
+
3
+ on: [push, pull_request]
4
+
5
+ jobs:
6
+ test:
7
+ runs-on: ubuntu-latest
8
+
9
+ # We want to run on external PRs, but not on our own internal PRs as they'll be run on push event
10
+ if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name != 'umbrellio/table_sync'
11
+
12
+ services:
13
+ postgres:
14
+ image: postgres
15
+ env:
16
+ POSTGRES_USER: root
17
+ POSTGRES_HOST_AUTH_METHOD: trust
18
+ options: >-
19
+ --health-cmd pg_isready
20
+ --health-interval 10s
21
+ --health-timeout 5s
22
+ --health-retries 5
23
+ ports:
24
+ - 5432:5432
25
+
26
+ env:
27
+ PGHOST: localhost
28
+ PGUSER: root
29
+
30
+ strategy:
31
+ fail-fast: false
32
+ matrix:
33
+ ruby: ["2.5", "2.6", "2.7", "3.0"]
34
+
35
+ name: ${{ matrix.ruby }}
36
+
37
+ steps:
38
+ - uses: actions/checkout@v2
39
+
40
+ - uses: ruby/setup-ruby@v1
41
+ with:
42
+ ruby-version: ${{ matrix.ruby }}
43
+ bundler-cache: true
44
+
45
+ - run: psql -c 'CREATE DATABASE table_sync_test'
46
+ - run: bundle exec rake bundle:audit
47
+ - run: bundle exec rubocop
48
+ - run: bundle exec rspec
49
+
50
+ - uses: coverallsapp/github-action@v1.1.2
51
+ with:
52
+ github-token: ${{ secrets.GITHUB_TOKEN }}
data/CHANGELOG.md CHANGED
@@ -1,16 +1,23 @@
1
1
  # Changelog
2
2
  All notable changes to this project will be documented in this file.
3
3
 
4
+ ## [5.0.0] - 2021-03-04
5
+ ### Fixed
6
+ - Fix `delete` events being broken when either `#attrs_for_routing_key` or `#attrs_for_metadata` was defined on a model.
7
+
8
+ ### Changed
9
+ - Instead of original attributes (default raw model attributes), use published attributes (as defined by `#attributes_for_sync` or `.table_sync_destroy_attributes`) for `TableSync.routing_key_callable` and `TableSync.routing_metadata_callable`.
10
+ - Send all original attributes for `delete` events instead of just PK.
11
+
4
12
  ## [4.2.2] - 2020-11-20
5
13
  ### Fixed
6
14
  - potential data corruption with batches
7
15
 
8
16
  ## [4.2.1] - 2020-11-20
9
17
  ### Fixed
10
- - bug with sorting data in handler, it was bad idea to use `.hash` replaced to `.to_s`
18
+ - bug with sorting data in handler, it was bad idea to use `.hash` replaced to `.to_s`
11
19
 
12
20
  ## [4.2.0] - 2020-11-19
13
-
14
21
  - No changes. Just stabilization release.
15
22
 
16
23
  ## [4.1.2] - 2020-11-19
@@ -42,9 +49,9 @@ All notable changes to this project will be documented in this file.
42
49
  ### Changed
43
50
  - .rubocop.yml
44
51
  - documentation
45
- - modules hierarchy (split receiving and publishing)
46
- `TableSync::Publisher` -> `TableSync::Publishing::Publisher`
47
- `TableSync::BatchPublisher` -> `TableSync::Publishing::BatchPublisher`
52
+ - modules hierarchy (split receiving and publishing)
53
+ `TableSync::Publisher` -> `TableSync::Publishing::Publisher`
54
+ `TableSync::BatchPublisher` -> `TableSync::Publishing::BatchPublisher`
48
55
  `TableSync::ReceivingHandler` -> `TableSync::Receiving::Handler`
49
56
  - made data batches processing as native
50
57
  - implemented callbacks as options
@@ -52,10 +59,10 @@ All notable changes to this project will be documented in this file.
52
59
  - type checking in options
53
60
  - `before_commit on: event, &block` -> `before_update(&block)` or `before_destroy(&block)`
54
61
  - `after_commit on: event, &block` -> `after_commit_on_update(&block)` or `after_commit_on_destroy(&block)`
55
- - changed parameters in some options:
56
- add `raw_data`
57
- `current_row` -> `row`
58
- ...
62
+ - changed parameters in some options:
63
+ add `raw_data`
64
+ `current_row` -> `row`
65
+ ...
59
66
  see documents for details
60
67
 
61
68
  ### Removed
data/Gemfile.lock CHANGED
@@ -1,72 +1,76 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- table_sync (4.2.2)
4
+ table_sync (5.0.0)
5
5
  memery
6
- rabbit_messaging (~> 0.3)
6
+ rabbit_messaging
7
7
  rails
8
8
  self_data
9
9
 
10
10
  GEM
11
11
  remote: https://rubygems.org/
12
12
  specs:
13
- actioncable (6.0.3.4)
14
- actionpack (= 6.0.3.4)
13
+ actioncable (6.1.3)
14
+ actionpack (= 6.1.3)
15
+ activesupport (= 6.1.3)
15
16
  nio4r (~> 2.0)
16
17
  websocket-driver (>= 0.6.1)
17
- actionmailbox (6.0.3.4)
18
- actionpack (= 6.0.3.4)
19
- activejob (= 6.0.3.4)
20
- activerecord (= 6.0.3.4)
21
- activestorage (= 6.0.3.4)
22
- activesupport (= 6.0.3.4)
18
+ actionmailbox (6.1.3)
19
+ actionpack (= 6.1.3)
20
+ activejob (= 6.1.3)
21
+ activerecord (= 6.1.3)
22
+ activestorage (= 6.1.3)
23
+ activesupport (= 6.1.3)
23
24
  mail (>= 2.7.1)
24
- actionmailer (6.0.3.4)
25
- actionpack (= 6.0.3.4)
26
- actionview (= 6.0.3.4)
27
- activejob (= 6.0.3.4)
25
+ actionmailer (6.1.3)
26
+ actionpack (= 6.1.3)
27
+ actionview (= 6.1.3)
28
+ activejob (= 6.1.3)
29
+ activesupport (= 6.1.3)
28
30
  mail (~> 2.5, >= 2.5.4)
29
31
  rails-dom-testing (~> 2.0)
30
- actionpack (6.0.3.4)
31
- actionview (= 6.0.3.4)
32
- activesupport (= 6.0.3.4)
33
- rack (~> 2.0, >= 2.0.8)
32
+ actionpack (6.1.3)
33
+ actionview (= 6.1.3)
34
+ activesupport (= 6.1.3)
35
+ rack (~> 2.0, >= 2.0.9)
34
36
  rack-test (>= 0.6.3)
35
37
  rails-dom-testing (~> 2.0)
36
38
  rails-html-sanitizer (~> 1.0, >= 1.2.0)
37
- actiontext (6.0.3.4)
38
- actionpack (= 6.0.3.4)
39
- activerecord (= 6.0.3.4)
40
- activestorage (= 6.0.3.4)
41
- activesupport (= 6.0.3.4)
39
+ actiontext (6.1.3)
40
+ actionpack (= 6.1.3)
41
+ activerecord (= 6.1.3)
42
+ activestorage (= 6.1.3)
43
+ activesupport (= 6.1.3)
42
44
  nokogiri (>= 1.8.5)
43
- actionview (6.0.3.4)
44
- activesupport (= 6.0.3.4)
45
+ actionview (6.1.3)
46
+ activesupport (= 6.1.3)
45
47
  builder (~> 3.1)
46
48
  erubi (~> 1.4)
47
49
  rails-dom-testing (~> 2.0)
48
50
  rails-html-sanitizer (~> 1.1, >= 1.2.0)
49
- activejob (6.0.3.4)
50
- activesupport (= 6.0.3.4)
51
+ activejob (6.1.3)
52
+ activesupport (= 6.1.3)
51
53
  globalid (>= 0.3.6)
52
- activemodel (6.0.3.4)
53
- activesupport (= 6.0.3.4)
54
- activerecord (6.0.3.4)
55
- activemodel (= 6.0.3.4)
56
- activesupport (= 6.0.3.4)
57
- activestorage (6.0.3.4)
58
- actionpack (= 6.0.3.4)
59
- activejob (= 6.0.3.4)
60
- activerecord (= 6.0.3.4)
54
+ activemodel (6.1.3)
55
+ activesupport (= 6.1.3)
56
+ activerecord (6.1.3)
57
+ activemodel (= 6.1.3)
58
+ activesupport (= 6.1.3)
59
+ activestorage (6.1.3)
60
+ actionpack (= 6.1.3)
61
+ activejob (= 6.1.3)
62
+ activerecord (= 6.1.3)
63
+ activesupport (= 6.1.3)
61
64
  marcel (~> 0.3.1)
62
- activesupport (6.0.3.4)
65
+ mimemagic (~> 0.3.2)
66
+ activesupport (6.1.3)
63
67
  concurrent-ruby (~> 1.0, >= 1.0.2)
64
- i18n (>= 0.7, < 2)
65
- minitest (~> 5.1)
66
- tzinfo (~> 1.1)
67
- zeitwerk (~> 2.2, >= 2.2.2)
68
+ i18n (>= 1.6, < 2)
69
+ minitest (>= 5.1)
70
+ tzinfo (~> 2.0)
71
+ zeitwerk (~> 2.3)
68
72
  amq-protocol (2.3.2)
69
- ast (2.4.1)
73
+ ast (2.4.2)
70
74
  builder (3.2.4)
71
75
  bundler-audit (0.7.0.1)
72
76
  bundler (>= 1.2.0, < 3)
@@ -74,28 +78,21 @@ GEM
74
78
  bunny (2.17.0)
75
79
  amq-protocol (~> 2.3, >= 2.3.1)
76
80
  coderay (1.1.3)
77
- concurrent-ruby (1.1.7)
78
- coveralls (0.8.23)
79
- json (>= 1.8, < 3)
80
- simplecov (~> 0.16.1)
81
- term-ansicolor (~> 1.3)
82
- thor (>= 0.19.4, < 2.0)
83
- tins (~> 1.6)
81
+ concurrent-ruby (1.1.8)
84
82
  crass (1.0.6)
85
83
  diff-lcs (1.4.4)
86
- docile (1.3.2)
84
+ docile (1.3.5)
87
85
  erubi (1.10.0)
88
86
  exception_notification (4.4.3)
89
87
  actionmailer (>= 4.0, < 7)
90
88
  activesupport (>= 4.0, < 7)
91
89
  globalid (0.4.2)
92
90
  activesupport (>= 4.2.0)
93
- i18n (1.8.5)
91
+ i18n (1.8.9)
94
92
  concurrent-ruby (~> 1.0)
95
- json (2.3.1)
96
93
  lamian (1.2.0)
97
94
  rails (>= 4.2)
98
- loofah (2.7.0)
95
+ loofah (2.9.0)
99
96
  crass (~> 1.0.2)
100
97
  nokogiri (>= 1.5.9)
101
98
  mail (2.7.1)
@@ -107,16 +104,17 @@ GEM
107
104
  method_source (1.0.0)
108
105
  mimemagic (0.3.5)
109
106
  mini_mime (1.0.2)
110
- mini_portile2 (2.4.0)
111
- minitest (5.14.2)
112
- nio4r (2.5.4)
113
- nokogiri (1.10.10)
114
- mini_portile2 (~> 2.4.0)
115
- parallel (1.19.2)
116
- parser (2.7.1.5)
107
+ mini_portile2 (2.5.0)
108
+ minitest (5.14.4)
109
+ nio4r (2.5.7)
110
+ nokogiri (1.11.1)
111
+ mini_portile2 (~> 2.5.0)
112
+ racc (~> 1.4)
113
+ parallel (1.20.1)
114
+ parser (3.0.0.0)
117
115
  ast (~> 2.4.1)
118
- pg (0.21.0)
119
- pry (0.13.1)
116
+ pg (1.2.3)
117
+ pry (0.14.0)
120
118
  coderay (~> 1.1)
121
119
  method_source (~> 1.0)
122
120
  rabbit_messaging (0.9.0)
@@ -126,88 +124,99 @@ GEM
126
124
  rails (>= 5.2)
127
125
  sneakers (~> 2.0)
128
126
  tainbox
127
+ racc (1.5.2)
129
128
  rack (2.2.3)
130
129
  rack-test (1.1.0)
131
130
  rack (>= 1.0, < 3)
132
- rails (6.0.3.4)
133
- actioncable (= 6.0.3.4)
134
- actionmailbox (= 6.0.3.4)
135
- actionmailer (= 6.0.3.4)
136
- actionpack (= 6.0.3.4)
137
- actiontext (= 6.0.3.4)
138
- actionview (= 6.0.3.4)
139
- activejob (= 6.0.3.4)
140
- activemodel (= 6.0.3.4)
141
- activerecord (= 6.0.3.4)
142
- activestorage (= 6.0.3.4)
143
- activesupport (= 6.0.3.4)
144
- bundler (>= 1.3.0)
145
- railties (= 6.0.3.4)
131
+ rails (6.1.3)
132
+ actioncable (= 6.1.3)
133
+ actionmailbox (= 6.1.3)
134
+ actionmailer (= 6.1.3)
135
+ actionpack (= 6.1.3)
136
+ actiontext (= 6.1.3)
137
+ actionview (= 6.1.3)
138
+ activejob (= 6.1.3)
139
+ activemodel (= 6.1.3)
140
+ activerecord (= 6.1.3)
141
+ activestorage (= 6.1.3)
142
+ activesupport (= 6.1.3)
143
+ bundler (>= 1.15.0)
144
+ railties (= 6.1.3)
146
145
  sprockets-rails (>= 2.0.0)
147
146
  rails-dom-testing (2.0.3)
148
147
  activesupport (>= 4.2.0)
149
148
  nokogiri (>= 1.6)
150
149
  rails-html-sanitizer (1.3.0)
151
150
  loofah (~> 2.3)
152
- railties (6.0.3.4)
153
- actionpack (= 6.0.3.4)
154
- activesupport (= 6.0.3.4)
151
+ railties (6.1.3)
152
+ actionpack (= 6.1.3)
153
+ activesupport (= 6.1.3)
155
154
  method_source
156
155
  rake (>= 0.8.7)
157
- thor (>= 0.20.3, < 2.0)
156
+ thor (~> 1.0)
158
157
  rainbow (3.0.0)
159
- rake (13.0.1)
160
- regexp_parser (1.8.1)
158
+ rake (13.0.3)
159
+ regexp_parser (2.1.1)
161
160
  rexml (3.2.4)
162
- rspec (3.9.0)
163
- rspec-core (~> 3.9.0)
164
- rspec-expectations (~> 3.9.0)
165
- rspec-mocks (~> 3.9.0)
166
- rspec-core (3.9.2)
167
- rspec-support (~> 3.9.3)
168
- rspec-expectations (3.9.2)
161
+ rspec (3.10.0)
162
+ rspec-core (~> 3.10.0)
163
+ rspec-expectations (~> 3.10.0)
164
+ rspec-mocks (~> 3.10.0)
165
+ rspec-core (3.10.1)
166
+ rspec-support (~> 3.10.0)
167
+ rspec-expectations (3.10.1)
169
168
  diff-lcs (>= 1.2.0, < 2.0)
170
- rspec-support (~> 3.9.0)
171
- rspec-mocks (3.9.1)
169
+ rspec-support (~> 3.10.0)
170
+ rspec-mocks (3.10.2)
172
171
  diff-lcs (>= 1.2.0, < 2.0)
173
- rspec-support (~> 3.9.0)
174
- rspec-support (3.9.3)
175
- rubocop (0.90.0)
172
+ rspec-support (~> 3.10.0)
173
+ rspec-support (3.10.2)
174
+ rubocop (1.11.0)
176
175
  parallel (~> 1.10)
177
- parser (>= 2.7.1.1)
176
+ parser (>= 3.0.0.0)
178
177
  rainbow (>= 2.2.2, < 4.0)
179
- regexp_parser (>= 1.7)
178
+ regexp_parser (>= 1.8, < 3.0)
180
179
  rexml
181
- rubocop-ast (>= 0.3.0, < 1.0)
180
+ rubocop-ast (>= 1.2.0, < 2.0)
182
181
  ruby-progressbar (~> 1.7)
183
- unicode-display_width (>= 1.4.0, < 2.0)
184
- rubocop-ast (0.7.1)
182
+ unicode-display_width (>= 1.4.0, < 3.0)
183
+ rubocop-ast (1.4.1)
185
184
  parser (>= 2.7.1.5)
186
- rubocop-config-umbrellio (0.90.0.93)
187
- rubocop (= 0.90.0)
188
- rubocop-performance (= 1.7.1)
189
- rubocop-rails (= 2.7.0)
190
- rubocop-rspec (= 1.42.0)
191
- rubocop-performance (1.7.1)
192
- rubocop (>= 0.82.0)
193
- rubocop-rails (2.7.0)
185
+ rubocop-config-umbrellio (1.11.0.40)
186
+ rubocop (= 1.11.0)
187
+ rubocop-performance (= 1.10.0)
188
+ rubocop-rails (= 2.9.1)
189
+ rubocop-rake (= 0.5.1)
190
+ rubocop-rspec (= 2.2.0)
191
+ rubocop-sequel (= 0.2.0)
192
+ rubocop-performance (1.10.0)
193
+ rubocop (>= 0.90.0, < 2.0)
194
+ rubocop-ast (>= 0.4.0)
195
+ rubocop-rails (2.9.1)
194
196
  activesupport (>= 4.2.0)
195
197
  rack (>= 1.1)
196
- rubocop (>= 0.87.0)
197
- rubocop-rspec (1.42.0)
198
- rubocop (>= 0.87.0)
199
- ruby-progressbar (1.10.1)
200
- ruby2_keywords (0.0.2)
198
+ rubocop (>= 0.90.0, < 2.0)
199
+ rubocop-rake (0.5.1)
200
+ rubocop
201
+ rubocop-rspec (2.2.0)
202
+ rubocop (~> 1.0)
203
+ rubocop-ast (>= 1.1.0)
204
+ rubocop-sequel (0.2.0)
205
+ rubocop (~> 1.0)
206
+ ruby-progressbar (1.11.0)
207
+ ruby2_keywords (0.0.4)
201
208
  self_data (1.2.1)
202
- sequel (5.37.0)
209
+ sequel (5.42.0)
203
210
  serverengine (2.0.7)
204
211
  sigdump (~> 0.2.2)
205
212
  sigdump (0.2.4)
206
- simplecov (0.16.1)
213
+ simplecov (0.21.2)
207
214
  docile (~> 1.1)
208
- json (>= 1.8, < 3)
209
- simplecov-html (~> 0.10.0)
210
- simplecov-html (0.10.2)
215
+ simplecov-html (~> 0.11)
216
+ simplecov_json_formatter (~> 0.1)
217
+ simplecov-html (0.12.3)
218
+ simplecov-lcov (0.8.0)
219
+ simplecov_json_formatter (0.1.2)
211
220
  sneakers (2.11.0)
212
221
  bunny (~> 2.12)
213
222
  concurrent-ruby (~> 1.0)
@@ -221,42 +230,36 @@ GEM
221
230
  actionpack (>= 4.0)
222
231
  activesupport (>= 4.0)
223
232
  sprockets (>= 3.0.0)
224
- sync (0.5.0)
225
233
  tainbox (2.1.2)
226
234
  activesupport
227
- term-ansicolor (1.7.1)
228
- tins (~> 1.0)
229
- thor (1.0.1)
230
- thread_safe (0.3.6)
231
- timecop (0.9.1)
232
- tins (1.25.0)
233
- sync
234
- tzinfo (1.2.7)
235
- thread_safe (~> 0.1)
236
- unicode-display_width (1.7.0)
235
+ thor (1.1.0)
236
+ timecop (0.9.4)
237
+ tzinfo (2.0.4)
238
+ concurrent-ruby (~> 1.0)
239
+ unicode-display_width (2.0.0)
237
240
  websocket-driver (0.7.3)
238
241
  websocket-extensions (>= 0.1.0)
239
242
  websocket-extensions (0.1.5)
240
- zeitwerk (2.4.0)
243
+ zeitwerk (2.4.2)
241
244
 
242
245
  PLATFORMS
243
246
  ruby
244
247
 
245
248
  DEPENDENCIES
246
- activejob (>= 6.0)
247
- activerecord (>= 6.0)
249
+ activejob
250
+ activerecord
248
251
  bundler
249
252
  bundler-audit
250
- coveralls (~> 0.8)
251
- pg (~> 0.18)
253
+ pg
252
254
  pry
253
255
  rake
254
- rspec (~> 3.8)
256
+ rspec
255
257
  rubocop-config-umbrellio
256
258
  sequel
257
- simplecov (~> 0.16)
259
+ simplecov
260
+ simplecov-lcov
258
261
  table_sync!
259
262
  timecop
260
263
 
261
264
  BUNDLED WITH
262
- 2.1.4
265
+ 2.2.11
data/README.md CHANGED
@@ -21,7 +21,7 @@ require 'table_sync'
21
21
  ## Usage
22
22
 
23
23
  - [Message protocol](docs/message_protocol.md)
24
- - [Publising](docs/publishing.md)
24
+ - [Publishing](docs/publishing.md)
25
25
  - [Receiving](docs/receiving.md)
26
26
  - [Notifications](docs/notifications.md)
27
27
 
@@ -1,9 +1,9 @@
1
1
  # Messages protocol
2
2
 
3
- ```
3
+ ```json
4
4
  {
5
- project_id: "pid",
6
- data: {
5
+ "project_id": "pid",
6
+ "data": {
7
7
  "event": "update",
8
8
  "model": "User",
9
9
  "version": 1.23,
data/docs/publishing.md CHANGED
@@ -1,7 +1,6 @@
1
1
  # Publishing changes
2
2
 
3
- Include `TableSync.sync(self)` into a Sequel or ActiveRecord model. `:if` and `:unless` are
4
- supported for Sequel and ActiveRecord
3
+ Include `TableSync.sync(self)` into a Sequel or ActiveRecord model. `:if` and `:unless` are supported for Sequel and ActiveRecord
5
4
 
6
5
  Functioning `Rails.cache` is required
7
6
 
@@ -9,37 +8,33 @@ Example:
9
8
 
10
9
  ```ruby
11
10
  class SomeModel < Sequel::Model
12
- TableSync.sync(self, { if: -> (*) { some_code } })
11
+ TableSync.sync(self, { if: -> (*) { some_code } })
13
12
  end
14
13
  ```
15
14
 
16
15
  #### #attributes_for_sync
17
16
 
18
- Models can implement `#attributes_for_sync` to override which attributes are published. If not
19
- present, all attributes are published
17
+ Models can implement `#attributes_for_sync` to override which attributes are published. If not present, all attributes are published
20
18
 
21
19
  #### #attrs_for_routing_key
22
20
 
23
- Models can implement `#attrs_for_routing_key` to override which attributes are given to routing_key_callable. If not present, default attributes are given
21
+ Models can implement `#attrs_for_routing_key` to override which attributes are given to `routing_key_callable`. If not present, published attributes are given
24
22
 
25
23
  #### #attrs_for_metadata
26
24
 
27
- Models can implement `#attrs_for_metadata` to override which attributes are given to metadata_callable. If not present, default attributes are given
25
+ Models can implement `#attrs_for_metadata` to override which attributes are given to `metadata_callable`. If not present, published attributes are given
28
26
 
29
27
  #### .table_sync_model_name
30
28
 
31
- Models can implement `.table_sync_model_name` class method to override the model name used for
32
- publishing events. Default is model class name
29
+ Models can implement `.table_sync_model_name` class method to override the model name used for publishing events. Default is model class name
33
30
 
34
31
  #### .table_sync_destroy_attributes(original_attributes)
35
32
 
36
- Models can implement `.table_sync_destroy_attributes` class method to override the attributes
37
- used for publishing destroy events. Default is object's primary key
33
+ Models can implement `.table_sync_destroy_attributes` class method to override the attributes used for publishing destroy events. Default is object's original attributes
38
34
 
39
35
  ## Configuration
40
36
 
41
- - `TableSync.publishing_job_class_callable` is a callable which should resolve to a ActiveJob
42
- subclass that calls TableSync back to actually publish changes (required)
37
+ - `TableSync.publishing_job_class_callable` is a callable which should resolve to a ActiveJob subclass that calls TableSync back to actually publish changes (required)
43
38
 
44
39
  Example:
45
40
 
@@ -51,11 +46,9 @@ class TableSync::Job < ActiveJob::Base
51
46
  end
52
47
  ```
53
48
 
54
- - `TableSync.batch_publishing_job_class_callable` is a callable which should resolve to a ActiveJob
55
- subclass that calls TableSync batch publisher back to actually publish changes (required for batch publisher)
49
+ - `TableSync.batch_publishing_job_class_callable` is a callable which should resolve to a ActiveJob subclass that calls TableSync batch publisher back to actually publish changes (required for batch publisher)
56
50
 
57
- - `TableSync.routing_key_callable` is a callable which resolves which routing key to use when
58
- publishing changes. It receives object class and attributes (required)
51
+ - `TableSync.routing_key_callable` is a callable which resolves which routing key to use when publishing changes. It receives object class and published attributes (required)
59
52
 
60
53
  Example:
61
54
 
@@ -63,9 +56,7 @@ Example:
63
56
  TableSync.routing_key_callable = -> (klass, attributes) { klass.gsub('::', '_').tableize }
64
57
  ```
65
58
 
66
- - `TableSync.routing_metadata_callable` is a callable that adds RabbitMQ headers which can be
67
- used in routing (optional). One possible way of using it is defining a headers exchange and
68
- routing rules based on key-value pairs (which correspond to sent headers)
59
+ - `TableSync.routing_metadata_callable` is a callable that adds RabbitMQ headers which can be used in routing (optional). It receives object class and published attributes. One possible way of using it is defining a headers exchange and routing rules based on key-value pairs (which correspond to sent headers)
69
60
 
70
61
  Example:
71
62
 
@@ -73,8 +64,7 @@ Example:
73
64
  TableSync.routing_metadata_callable = -> (klass, attributes) { attributes.slice("project_id") }
74
65
  ```
75
66
 
76
- - `TableSync.exchange_name` defines the exchange name used for publishing (optional, falls back
77
- to default Rabbit gem configuration).
67
+ - `TableSync.exchange_name` defines the exchange name used for publishing (optional, falls back to default Rabbit gem configuration).
78
68
 
79
69
  - `TableSync.notifier` is a module that provides publish and recieve notifications.
80
70
 
@@ -87,9 +77,7 @@ where state is one of `:created / :updated / :destroyed` and `confirm` is Rabbit
87
77
 
88
78
  You can use `TableSync::BatchPublisher` to publish changes in batches (array of hashes in `attributes`).
89
79
 
90
- When using `TableSync::BatchPublisher`,` TableSync.routing_key_callable` is called as follows:
91
- `TableSync.routing_key_callable.call(klass, {})`, i.e. empty hash is passed instead of attributes.
92
- And `TableSync.routing_metadata_callable` is not called at all: metadata is set to empty hash.
80
+ When using `TableSync::BatchPublisher`,` TableSync.routing_key_callable` is called as follows: `TableSync.routing_key_callable.call(klass, {})`, i.e. empty hash is passed instead of attributes. And `TableSync.routing_metadata_callable` is not called at all: metadata is set to empty hash.
93
81
 
94
82
  `TableSync::BatchPublisher.new(object_class, original_attributes_array, **options)`, where `original_attributes_array` is an array with hash of attributes of published objects and `options` is a hash of options.
95
83
 
@@ -119,9 +107,7 @@ TableSync::BatchPublisher.new(
119
107
 
120
108
  С помощью класса `TableSync::BatchPublisher` вы можете опубликовать изменения батчами (массивом в `attributes`).
121
109
 
122
- При использовании `TableSync::BatchPublisher`, `TableSync.routing_key_callable` вызывается следующим образом:
123
- `TableSync.routing_key_callable.call(klass, {})`, то есть вместо аттрибутов передается пустой хэш.
124
- А `TableSync.routing_metadata_callable` не вызывается вовсе: в метадате устанавливается пустой хэш.
110
+ При использовании `TableSync::BatchPublisher`, `TableSync.routing_key_callable` вызывается следующим образом: `TableSync.routing_key_callable.call(klass, {})`, то есть вместо аттрибутов передается пустой хэш. А `TableSync.routing_metadata_callable` не вызывается вовсе: в метадате устанавливается пустой хэш.
125
111
 
126
112
  `TableSync::BatchPublisher.new(object_class, original_attributes_array, **options)`, где `original_attributes_array` - массив с аттрибутами публикуемых объектов и `options`- это хэш с дополнительными опциями.
127
113
 
@@ -144,4 +130,4 @@ TableSync::BatchPublisher.new(
144
130
  headers: { key: :value },
145
131
  event: :destroy,
146
132
  )
147
- ```
133
+ ```
@@ -29,14 +29,6 @@ class TableSync::Publishing::BasePublisher
29
29
  object_class.method_defined?(:attributes_for_sync)
30
30
  end
31
31
 
32
- memoize def attrs_for_routing_key_defined?
33
- object_class.method_defined?(:attrs_for_routing_key)
34
- end
35
-
36
- memoize def attrs_for_metadata_defined?
37
- object_class.method_defined?(:attrs_for_metadata)
38
- end
39
-
40
32
  def resolve_routing_key
41
33
  routing_key_callable.call(object_class.name, attrs_for_routing_key)
42
34
  end
@@ -57,17 +49,21 @@ class TableSync::Publishing::BasePublisher
57
49
  def filter_safe_for_serialization(object)
58
50
  case object
59
51
  when Array
60
- object.map(&method(:filter_safe_for_serialization)).select(&method(:object_mapped?))
52
+ object.each_with_object([]) do |value, memo|
53
+ value = filter_safe_for_serialization(value)
54
+ memo << value if object_mapped?(value)
55
+ end
61
56
  when Hash
62
- object
63
- .transform_keys(&method(:filter_safe_for_serialization))
64
- .transform_values(&method(:filter_safe_hash_values))
65
- .select { |*objects| objects.all?(&method(:object_mapped?)) }
57
+ object.each_with_object({}) do |(key, value), memo|
58
+ key = filter_safe_for_serialization(key)
59
+ value = filter_safe_hash_values(value)
60
+ memo[key] = value if object_mapped?(key) && object_mapped?(value)
61
+ end
66
62
  when Float::INFINITY
67
63
  NOT_MAPPED
68
64
  when *BASE_SAFE_JSON_TYPES
69
65
  object
70
- else
66
+ else # rubocop:disable Lint/DuplicateBranch
71
67
  NOT_MAPPED
72
68
  end
73
69
  end
@@ -9,14 +9,8 @@ class TableSync::Publishing::Publisher < TableSync::Publishing::BasePublisher
9
9
  @original_attributes = filter_safe_for_serialization(original_attributes.deep_symbolize_keys)
10
10
  @confirm = opts.fetch(:confirm, true)
11
11
  @debounce_time = opts[:debounce_time]&.seconds || DEBOUNCE_TIME
12
-
13
- if opts[:destroyed].nil?
14
- @state = opts.fetch(:state, :updated).to_sym
15
- validate_state
16
- else
17
- # TODO Legacy job support, remove
18
- @state = opts[:destroyed] ? :destroyed : :updated
19
- end
12
+ @state = opts.fetch(:state, :updated).to_sym
13
+ validate_state
20
14
  end
21
15
 
22
16
  def publish
@@ -46,17 +40,23 @@ class TableSync::Publishing::Publisher < TableSync::Publishing::BasePublisher
46
40
  attr_reader :debounce_time
47
41
 
48
42
  def attrs_for_callables
49
- original_attributes
43
+ attributes_for_sync
50
44
  end
51
45
 
52
46
  def attrs_for_routing_key
53
- return object.attrs_for_routing_key if attrs_for_routing_key_defined?
54
- attrs_for_callables
47
+ if object.respond_to?(:attrs_for_routing_key)
48
+ object.attrs_for_routing_key
49
+ else
50
+ attrs_for_callables
51
+ end
55
52
  end
56
53
 
57
54
  def attrs_for_metadata
58
- return object.attrs_for_metadata if attrs_for_metadata_defined?
59
- attrs_for_callables
55
+ if object.respond_to?(:attrs_for_metadata)
56
+ object.attrs_for_metadata
57
+ else
58
+ attrs_for_callables
59
+ end
60
60
  end
61
61
 
62
62
  def job_callable
@@ -85,12 +85,12 @@ class TableSync::Publishing::Publisher < TableSync::Publishing::BasePublisher
85
85
  }
86
86
  end
87
87
 
88
- def attributes_for_sync
88
+ memoize def attributes_for_sync
89
89
  if destroyed?
90
90
  if object_class.respond_to?(:table_sync_destroy_attributes)
91
91
  object_class.table_sync_destroy_attributes(original_attributes)
92
92
  else
93
- needle
93
+ original_attributes
94
94
  end
95
95
  elsif attributes_for_sync_defined?
96
96
  object.attributes_for_sync
@@ -82,7 +82,7 @@ class TableSync::Receiving::Handler < Rabbit::EventHandler
82
82
  row[after] = row.delete(before)
83
83
  end
84
84
 
85
- config.except(row: row).each(&row.method(:delete))
85
+ config.except(row: row).each { |x| row.delete(x) }
86
86
 
87
87
  row.merge!(config.additional_data(row: row))
88
88
 
@@ -98,7 +98,8 @@ class TableSync::Receiving::Handler < Rabbit::EventHandler
98
98
 
99
99
  def validate_data(data, target_keys:)
100
100
  data.each do |row|
101
- next if target_keys.all?(&row.keys.method(:include?))
101
+ next if target_keys.all? { |x| row.key?(x) }
102
+
102
103
  raise TableSync::DataError.new(
103
104
  data, target_keys, "Some target keys not found in received attributes!"
104
105
  )
@@ -110,7 +111,7 @@ class TableSync::Receiving::Handler < Rabbit::EventHandler
110
111
 
111
112
  keys_sample = data[0].keys
112
113
  keys_diff = data.each_with_object(Set.new) do |row, set|
113
- (row.keys - keys_sample | keys_sample - row.keys).each(&set.method(:add))
114
+ (row.keys - keys_sample | keys_sample - row.keys).each { |x| set.add(x) }
114
115
  end
115
116
 
116
117
  unless keys_diff.empty?
@@ -96,7 +96,7 @@ module TableSync::Receiving::Model
96
96
  end
97
97
  end
98
98
 
99
- result = query.destroy_all.map(&method(:row_to_hash))
99
+ result = query.destroy_all.map { |x| row_to_hash(x) }
100
100
 
101
101
  if result.size > data.size
102
102
  raise TableSync::DestroyError.new(data: data, target_keys: target_keys, result: result)
@@ -54,8 +54,8 @@ class TableSync::Utils::InterfaceChecker
54
54
  end
55
55
 
56
56
  def filter(parameters)
57
- # for req and block parameters types we can ignore names
58
- parameters.map { |param| %i[req block].include?(param.first) ? [param.first] : param }
57
+ ignored_keys = %i[req block] # for req and block parameters types we can ignore names
58
+ parameters.map { |param| ignored_keys.include?(param.first) ? [param.first] : param }
59
59
  end
60
60
  end
61
61
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module TableSync
4
- VERSION = "4.2.2"
4
+ VERSION = "5.0.0"
5
5
  end
data/table_sync.gemspec CHANGED
@@ -27,18 +27,18 @@ Gem::Specification.new do |spec|
27
27
  end
28
28
 
29
29
  spec.add_runtime_dependency "memery"
30
- spec.add_runtime_dependency "rabbit_messaging", "~> 0.3"
30
+ spec.add_runtime_dependency "rabbit_messaging"
31
31
  spec.add_runtime_dependency "rails"
32
32
  spec.add_runtime_dependency "self_data"
33
33
 
34
- spec.add_development_dependency "coveralls", "~> 0.8"
35
- spec.add_development_dependency "rspec", "~> 3.8"
34
+ spec.add_development_dependency "rspec"
36
35
  spec.add_development_dependency "rubocop-config-umbrellio"
37
- spec.add_development_dependency "simplecov", "~> 0.16"
36
+ spec.add_development_dependency "simplecov"
37
+ spec.add_development_dependency "simplecov-lcov"
38
38
 
39
- spec.add_development_dependency "activejob", ">= 6.0"
40
- spec.add_development_dependency "activerecord", ">= 6.0"
41
- spec.add_development_dependency "pg", "~> 0.18"
39
+ spec.add_development_dependency "activejob"
40
+ spec.add_development_dependency "activerecord"
41
+ spec.add_development_dependency "pg"
42
42
  spec.add_development_dependency "sequel"
43
43
  spec.add_development_dependency "timecop"
44
44
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: table_sync
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.2.2
4
+ version: 5.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Umbrellio
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-11-20 00:00:00.000000000 Z
11
+ date: 2021-03-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: memery
@@ -28,16 +28,16 @@ dependencies:
28
28
  name: rabbit_messaging
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: '0.3'
33
+ version: '0'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - "~>"
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: '0.3'
40
+ version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rails
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -67,35 +67,35 @@ dependencies:
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
- name: coveralls
70
+ name: rspec
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - "~>"
73
+ - - ">="
74
74
  - !ruby/object:Gem::Version
75
- version: '0.8'
75
+ version: '0'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - "~>"
80
+ - - ">="
81
81
  - !ruby/object:Gem::Version
82
- version: '0.8'
82
+ version: '0'
83
83
  - !ruby/object:Gem::Dependency
84
- name: rspec
84
+ name: rubocop-config-umbrellio
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - "~>"
87
+ - - ">="
88
88
  - !ruby/object:Gem::Version
89
- version: '3.8'
89
+ version: '0'
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - "~>"
94
+ - - ">="
95
95
  - !ruby/object:Gem::Version
96
- version: '3.8'
96
+ version: '0'
97
97
  - !ruby/object:Gem::Dependency
98
- name: rubocop-config-umbrellio
98
+ name: simplecov
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
101
  - - ">="
@@ -109,61 +109,61 @@ dependencies:
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
111
  - !ruby/object:Gem::Dependency
112
- name: simplecov
112
+ name: simplecov-lcov
113
113
  requirement: !ruby/object:Gem::Requirement
114
114
  requirements:
115
- - - "~>"
115
+ - - ">="
116
116
  - !ruby/object:Gem::Version
117
- version: '0.16'
117
+ version: '0'
118
118
  type: :development
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
- - - "~>"
122
+ - - ">="
123
123
  - !ruby/object:Gem::Version
124
- version: '0.16'
124
+ version: '0'
125
125
  - !ruby/object:Gem::Dependency
126
126
  name: activejob
127
127
  requirement: !ruby/object:Gem::Requirement
128
128
  requirements:
129
129
  - - ">="
130
130
  - !ruby/object:Gem::Version
131
- version: '6.0'
131
+ version: '0'
132
132
  type: :development
133
133
  prerelease: false
134
134
  version_requirements: !ruby/object:Gem::Requirement
135
135
  requirements:
136
136
  - - ">="
137
137
  - !ruby/object:Gem::Version
138
- version: '6.0'
138
+ version: '0'
139
139
  - !ruby/object:Gem::Dependency
140
140
  name: activerecord
141
141
  requirement: !ruby/object:Gem::Requirement
142
142
  requirements:
143
143
  - - ">="
144
144
  - !ruby/object:Gem::Version
145
- version: '6.0'
145
+ version: '0'
146
146
  type: :development
147
147
  prerelease: false
148
148
  version_requirements: !ruby/object:Gem::Requirement
149
149
  requirements:
150
150
  - - ">="
151
151
  - !ruby/object:Gem::Version
152
- version: '6.0'
152
+ version: '0'
153
153
  - !ruby/object:Gem::Dependency
154
154
  name: pg
155
155
  requirement: !ruby/object:Gem::Requirement
156
156
  requirements:
157
- - - "~>"
157
+ - - ">="
158
158
  - !ruby/object:Gem::Version
159
- version: '0.18'
159
+ version: '0'
160
160
  type: :development
161
161
  prerelease: false
162
162
  version_requirements: !ruby/object:Gem::Requirement
163
163
  requirements:
164
- - - "~>"
164
+ - - ">="
165
165
  - !ruby/object:Gem::Version
166
- version: '0.18'
166
+ version: '0'
167
167
  - !ruby/object:Gem::Dependency
168
168
  name: sequel
169
169
  requirement: !ruby/object:Gem::Requirement
@@ -256,10 +256,10 @@ executables: []
256
256
  extensions: []
257
257
  extra_rdoc_files: []
258
258
  files:
259
+ - ".github/workflows/ci.yml"
259
260
  - ".gitignore"
260
261
  - ".rspec"
261
262
  - ".rubocop.yml"
262
- - ".travis.yml"
263
263
  - CHANGELOG.md
264
264
  - Gemfile
265
265
  - Gemfile.lock
@@ -317,7 +317,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
317
317
  - !ruby/object:Gem::Version
318
318
  version: '0'
319
319
  requirements: []
320
- rubygems_version: 3.2.0.rc.1
320
+ rubygems_version: 3.2.11
321
321
  signing_key:
322
322
  specification_version: 4
323
323
  summary: DB Table synchronization between microservices based on Model's event system
data/.travis.yml DELETED
@@ -1,34 +0,0 @@
1
- language: ruby
2
-
3
- rvm:
4
- - 2.5
5
- - 2.6
6
- - 2.7
7
- - ruby-head
8
-
9
- matrix:
10
- fast_finish: true
11
- allow_failures:
12
- - rvm: ruby-head
13
-
14
- sudo: false
15
-
16
- dist: xenial
17
-
18
- cache: bundler
19
-
20
- services:
21
- - postgresql
22
-
23
- addons:
24
- postgresql: "10"
25
-
26
- before_install: gem install bundler
27
-
28
- before_script:
29
- - psql -c 'create database table_sync_test;' -U postgres
30
-
31
- script:
32
- - bundle exec rake bundle:audit
33
- - bundle exec rubocop
34
- - bundle exec rspec