table_sync 1.5.0 → 1.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -1
- data/.travis.yml +0 -1
- data/CHANGELOG.md +6 -0
- data/docs/synopsis.md +9 -0
- data/lib/table_sync/config.rb +5 -0
- data/lib/table_sync/config_decorator.rb +3 -0
- data/lib/table_sync/event_actions.rb +7 -4
- data/lib/table_sync/version.rb +1 -1
- data/log/.keep +0 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7248151a812c8fce2f5d0dc91e12dba3a05eec7994fa3913df2030e4db54e026
|
4
|
+
data.tar.gz: 3b069e69156436729608fa6a12b4b914a57dd2c9af9dec0034664801f3c1138e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5958da943ef7b3c157e0c46448a48ee6ea76ffb7dfa2b3ca6b605b4035dd76513c6573299ba47361f289ef0b33414c2022f451903b38c792ee1b78db0376c7c4
|
7
|
+
data.tar.gz: 7178c41e1f6d9f7e9582db11b0b1090efa443ded61f6f929e7d0d5f3fc1c565d70d2209509db1b6356fe744fd72574745b0fae2e9c7b9074639163ad9ad677ec
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
data/CHANGELOG.md
ADDED
data/docs/synopsis.md
CHANGED
@@ -203,6 +203,15 @@ This method implements logic of mapping `source` to `to_table` and allows custom
|
|
203
203
|
You can use one `source` for a lot of `to_table`.
|
204
204
|
|
205
205
|
The following options are available inside the block:
|
206
|
+
- `on_destroy` - defines a custom logic and behavior for `destroy` event:
|
207
|
+
- definition:
|
208
|
+
```ruby
|
209
|
+
on_destroy do |attributes:, target_keys:|
|
210
|
+
# your code here
|
211
|
+
end
|
212
|
+
```
|
213
|
+
- `target_keys:` - primary keys or unique keys;
|
214
|
+
- `attributes:` - received model attributes;
|
206
215
|
- `only` - whitelist for receiving attributes
|
207
216
|
- `skip` - return truthy value to skip the row
|
208
217
|
- `target_keys` - primary keys or unique keys
|
data/lib/table_sync/config.rb
CHANGED
@@ -17,6 +17,7 @@ module TableSync
|
|
17
17
|
@rest_key = :rest
|
18
18
|
@version_key = :version
|
19
19
|
@first_sync_time_key = nil
|
20
|
+
@on_destroy = nil
|
20
21
|
target_keys(model.primary_keys)
|
21
22
|
end
|
22
23
|
|
@@ -55,6 +56,10 @@ module TableSync
|
|
55
56
|
callback_registry.register_callback(block, kind: :after_commit, event: on.to_sym)
|
56
57
|
end
|
57
58
|
|
59
|
+
def on_destroy(&block)
|
60
|
+
block_given? ? @on_destroy = block : @on_destroy
|
61
|
+
end
|
62
|
+
|
58
63
|
check_and_set_column_key = proc do |key|
|
59
64
|
key = key.to_sym
|
60
65
|
raise "#{model.inspect} doesn't have key: #{key}" unless model.columns.include?(key)
|
@@ -4,6 +4,9 @@ module TableSync
|
|
4
4
|
# rubocop:disable Style/MissingRespondToMissing, Style/MethodMissingSuper
|
5
5
|
class ConfigDecorator
|
6
6
|
include ::TableSync::EventActions
|
7
|
+
extend Forwardable
|
8
|
+
|
9
|
+
def_delegators :@config, :on_destroy
|
7
10
|
|
8
11
|
def initialize(config, handler)
|
9
12
|
@config = config
|
@@ -40,10 +40,13 @@ module TableSync
|
|
40
40
|
cb[attributes]
|
41
41
|
end
|
42
42
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
43
|
+
if on_destroy
|
44
|
+
on_destroy.call(attributes: attributes, target_keys: target_keys)
|
45
|
+
else
|
46
|
+
results = model.destroy(target_attributes)
|
47
|
+
return if results.empty?
|
48
|
+
raise TableSync::DestroyError.new(target_attributes) if results.size != 1
|
49
|
+
end
|
47
50
|
|
48
51
|
@config.model.after_commit do
|
49
52
|
@config.callback_registry.get_callbacks(kind: :after_commit, event: :destroy).each do |cb|
|
data/lib/table_sync/version.rb
CHANGED
data/log/.keep
ADDED
File without changes
|
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: 1.
|
4
|
+
version: 1.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Umbrellio
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-07-
|
11
|
+
date: 2019-07-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: memery
|
@@ -246,6 +246,7 @@ files:
|
|
246
246
|
- ".rspec"
|
247
247
|
- ".rubocop.yml"
|
248
248
|
- ".travis.yml"
|
249
|
+
- CHANGELOG.md
|
249
250
|
- Gemfile
|
250
251
|
- LICENSE.md
|
251
252
|
- README.md
|
@@ -269,6 +270,7 @@ files:
|
|
269
270
|
- lib/table_sync/publisher.rb
|
270
271
|
- lib/table_sync/receiving_handler.rb
|
271
272
|
- lib/table_sync/version.rb
|
273
|
+
- log/.keep
|
272
274
|
- table_sync.gemspec
|
273
275
|
homepage: https://github.com/umbrellio/table_sync
|
274
276
|
licenses:
|