table_sync 1.5.0 → 1.6.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: 034afda2dc0f9674a75c99f06074dc6f2c4b72da2a367bb70fba3182fb937a6c
4
- data.tar.gz: bc3dd822dff7ae6d4671dbfc2555d9b5e8aad61516cde66fd8d3406fd291d241
3
+ metadata.gz: 7248151a812c8fce2f5d0dc91e12dba3a05eec7994fa3913df2030e4db54e026
4
+ data.tar.gz: 3b069e69156436729608fa6a12b4b914a57dd2c9af9dec0034664801f3c1138e
5
5
  SHA512:
6
- metadata.gz: 3aeb6df3c43d777cd2a4d2377fd1e81c67b1f90afc9e9954e1407e87af21095cf0efe0179d5b4a6d9ee6edf0988305475bb2b7542368cf0ec50ce9a12e3b28e0
7
- data.tar.gz: afdaecc73c86abefc056af4770b2c0ff0d9ca11ba480fb64818a36bec4aa3ee42246fae404f8e8ca4892e0bfcd9b496b666c859442c7cfc0fe1c0d47121cd74f
6
+ metadata.gz: 5958da943ef7b3c157e0c46448a48ee6ea76ffb7dfa2b3ca6b605b4035dd76513c6573299ba47361f289ef0b33414c2022f451903b38c792ee1b78db0376c7c4
7
+ data.tar.gz: 7178c41e1f6d9f7e9582db11b0b1090efa443ded61f6f929e7d0d5f3fc1c565d70d2209509db1b6356fe744fd72574745b0fae2e9c7b9074639163ad9ad677ec
data/.gitignore CHANGED
@@ -1,3 +1,5 @@
1
+ /log/*
2
+ !/log/.keep
1
3
  /.bundle/
2
4
  /.yardoc
3
5
  /_yardoc/
@@ -8,5 +10,4 @@
8
10
  /tmp/
9
11
  .ruby-version
10
12
  Gemfile.lock
11
- /log/
12
13
  *.gem
data/.travis.yml CHANGED
@@ -20,7 +20,6 @@ before_install: gem install bundler
20
20
  before_script:
21
21
  - psql -c 'create database table_sync_test;' -U postgres
22
22
  script:
23
- - mkdir log
24
23
  - bundle exec rake bundle:audit
25
24
  - bundle exec rubocop
26
25
  - bundle exec rspec
data/CHANGELOG.md ADDED
@@ -0,0 +1,6 @@
1
+ # Changelog
2
+ All notable changes to this project will be documented in this file.
3
+
4
+ ## [1.6.0] - 2019-07-08
5
+ ### Added
6
+ - `on_destroy` - defines a custom logic and behavior for `destroy` event;
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
@@ -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
- results = model.destroy(target_attributes)
44
-
45
- return if results.empty?
46
- raise TableSync::DestroyError.new(target_attributes) if results.size != 1
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|
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module TableSync
4
- VERSION = "1.5.0"
4
+ VERSION = "1.6.0"
5
5
  end
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.5.0
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-02 00:00:00.000000000 Z
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: