table_sync 1.10.0 → 1.11.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: '08f6482ff6549370e3855dced47343465678ed5b095f3c613363c4a6bbe743ef'
4
- data.tar.gz: 59a541d16d2d2f0ae6e7f317b798aa1d3d8e4c7cc7a8dcd5e8696d6a892288c5
3
+ metadata.gz: 86c13b07f0c63f70ecd2acc80fca50cdd57e0c3682ad5d7bafa56ef69b94185d
4
+ data.tar.gz: 8e01d572ffa14629317b248e0090bab8bde89e3dee513434b51b0bc897ceb02f
5
5
  SHA512:
6
- metadata.gz: 623bf01e97409e583b008890f458d8bf8646254e373bc1ee4f9406ef54f4cb470957437c284e5309b0b5b0a5285589a7713beb7e64f4935d2473d71180f45dff
7
- data.tar.gz: ce06f381c631a0ce48eabf873b239f48310fe6bc120d2c4152c8ce0a81e47101fb16ed256eb00d4e89d6a32f24dfb8c6b01bbfee9412104bf4d0c8d4f2c0ed10
6
+ metadata.gz: 741c3d1904400d34d1e3f0fb03eac24d9b954544744dd0736fa672a3a94751b09e0b221867d4e625749a8301f674e527f82cf62d297ccb1e4f4d1c09b6ad45f9
7
+ data.tar.gz: 62ee1dc7912c8c301105f0134e0a8dbef9f45ba3ca9d82ff321127f9daedd03129f261ee7af8b738da029d3f5d012627c2cbbd0f9e759826218f1b2c70f5c0b2
data/CHANGELOG.md CHANGED
@@ -1,6 +1,11 @@
1
1
  # Changelog
2
2
  All notable changes to this project will be documented in this file.
3
3
 
4
+ ## [1.11.0] - 2019-09-11
5
+ ### Added
6
+ - Receiving: inconsistent events raises `TableSync::UnprovidedEventTargetKeysError`
7
+ (events that include only some of the target keys (or none))
8
+
4
9
  ## [1.10.0] - 2019-08-28
5
10
  ### Added
6
11
  - convert symbolic values to strings in hashes to support older versions of activejob
@@ -16,15 +16,26 @@ module TableSync
16
16
  end
17
17
  end
18
18
 
19
+ class UndefinedConfig < Error
20
+ def initialize(model)
21
+ super("Config not defined for model; model: #{model.inspect}")
22
+ end
23
+ end
24
+
19
25
  class DestroyError < Error
20
26
  def initialize(data)
21
27
  super("Destroy has changed more than 1 row; data: #{data.inspect}")
22
28
  end
23
29
  end
24
30
 
25
- class UndefinedConfig < Error
26
- def initialize(model)
27
- super("Config not defined for model; model: #{model.inspect}")
31
+ class UnprovidedEventTargetKeysError < Error
32
+ # @param target_keys [Array<Symbol,String>]
33
+ # @param target_attributes [Hash<Symbol|String,Any>]
34
+ def initialize(target_keys, target_attributes)
35
+ super(<<~MSG.squish)
36
+ Some target keys not found in received attributes!
37
+ (Expects: #{target_keys}, Actual: #{target_attributes.keys})
38
+ MSG
28
39
  end
29
40
  end
30
41
  end
@@ -3,6 +3,12 @@
3
3
  module TableSync
4
4
  module EventActions
5
5
  def update(data) # rubocop:disable Metrics/MethodLength
6
+ data.each_value do |attribute_set|
7
+ attribute_set.each do |attributes|
8
+ prevent_incomplete_event!(attributes)
9
+ end
10
+ end
11
+
6
12
  model.transaction do
7
13
  args = {
8
14
  data: data,
@@ -21,7 +27,7 @@ module TableSync
21
27
  end
22
28
 
23
29
  return if results.empty?
24
- raise TableSync::UpsertError.new(**args) unless correct_keys?(results)
30
+ raise TableSync::UpsertError.new(**args) unless expected_update_result?(results)
25
31
 
26
32
  @config.model.after_commit do
27
33
  @config.callback_registry.get_callbacks(kind: :after_commit, event: :update).each do |cb|
@@ -33,7 +39,8 @@ module TableSync
33
39
 
34
40
  def destroy(data)
35
41
  attributes = data.first || {}
36
- target_attributes = attributes.select { |key| target_keys.include?(key) }
42
+ target_attributes = attributes.select { |key, _value| target_keys.include?(key) }
43
+ prevent_incomplete_event!(target_attributes)
37
44
 
38
45
  model.transaction do
39
46
  @config.callback_registry.get_callbacks(kind: :before_commit, event: :destroy).each do |cb|
@@ -56,8 +63,14 @@ module TableSync
56
63
  end
57
64
  end
58
65
 
59
- def correct_keys?(query_results)
66
+ def expected_update_result?(query_results)
60
67
  query_results.uniq { |d| d.slice(*target_keys) }.size == query_results.size
61
68
  end
69
+
70
+ def prevent_incomplete_event!(attributes)
71
+ unless target_keys.all?(&attributes.keys.method(:include?))
72
+ raise TableSync::UnprovidedEventTargetKeysError.new(target_keys, attributes)
73
+ end
74
+ end
62
75
  end
63
76
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module TableSync
4
- VERSION = "1.10.0"
4
+ VERSION = "1.11.0"
5
5
  end
data/table_sync.gemspec CHANGED
@@ -32,7 +32,7 @@ Gem::Specification.new do |spec|
32
32
 
33
33
  spec.add_development_dependency "coveralls", "~> 0.8"
34
34
  spec.add_development_dependency "rspec", "~> 3.8"
35
- spec.add_development_dependency "rubocop-config-umbrellio", "~> 0.70"
35
+ spec.add_development_dependency "rubocop-config-umbrellio", "~> 0.74"
36
36
  spec.add_development_dependency "simplecov", "~> 0.16"
37
37
 
38
38
  spec.add_development_dependency "activejob", ">= 4.2.11"
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.10.0
4
+ version: 1.11.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-08-28 00:00:00.000000000 Z
11
+ date: 2019-09-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: memery
@@ -86,14 +86,14 @@ dependencies:
86
86
  requirements:
87
87
  - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: '0.70'
89
+ version: '0.74'
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: '0.70'
96
+ version: '0.74'
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: simplecov
99
99
  requirement: !ruby/object:Gem::Requirement