tp_record_optimistic 0.1.0 → 0.2.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
  SHA1:
3
- metadata.gz: 2651fb66b105f0ce911a99fa4d55c2fe558d3955
4
- data.tar.gz: c31933d9f9d104fddc5653299ff1261a35542b75
3
+ metadata.gz: 18b8156926d15c46a8ffdc916f1b093cf50c9aeb
4
+ data.tar.gz: 46322a6464c78088d2aff604926e12d7307f6f7e
5
5
  SHA512:
6
- metadata.gz: ff8a74c73a85a246848b9872c91aae1bb03e0801ded4883c708981feb9edeff0821a8271135fb44b6f3624cfd6079a45bc11f6f449e080bccc62684a8e46c51b
7
- data.tar.gz: 7d757fbd311277e9c83b0c21f73eae4c4b5fc3d42b79ebb4897f2c3b9ecfc7aff22edba42814b6e2cdd96243960034b7c3698b33e4c30f9d9456d775d60abbcb
6
+ metadata.gz: 8e76fbe00a06098a7117b18dc78b1119cbe37ba50baa8ae706e2baf498db5ff958aa6876ad8dcb19c9e1527fa483168afca19f9bebc34308ad5c0618793a4abd
7
+ data.tar.gz: e10d80cad8300d6e21836d4ab1b9288cc05bc6b6fe18358749322db748b0bb2953c1f42239ac04b6b7f33545e04c448d3987bd2af0207a9311db02512ac05be3
data/README.rdoc CHANGED
@@ -1,3 +1,20 @@
1
1
  = TPOptimistic
2
2
 
3
- Treat duplicated error is recovery like error
3
+ This gem improve the ActiveRecord to trate ActiveRecord::RecordNotUnique with optimistic behavior
4
+
5
+ exemplo:
6
+
7
+ def sample
8
+ Bar.create(uuid: '5ea880de-e4ce-4770-8d10-c89bac181e40', other: 'bla bla')
9
+ bar = Bar.create(uuid: '5ea880de-e4ce-4770-8d10-c89bac181e40', other: 'bla bla')
10
+
11
+ #UNIQUE constraint failed
12
+ bar.errors
13
+ end
14
+
15
+
16
+ def other_sample
17
+ Bar.create!(uuid: '5ea880de-e4ce-4770-8d10-c89bac181e40', other: 'bla bla')
18
+ #ActiveRecord::RecordInvalid UNIQUE constraint failed
19
+ Bar.create!(uuid: '5ea880de-e4ce-4770-8d10-c89bac181e40', other: 'bla bla')
20
+ end
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module TPRecordOptimistic
3
- VERSION = '0.1.0'
3
+ VERSION = '0.2.0'
4
4
  end
@@ -18,6 +18,19 @@ module TPRecordOptimistic
18
18
  return false
19
19
  end
20
20
 
21
+ def save!(*args)
22
+ super(*args)
23
+ end
24
+
25
+ alias old_save! save!
26
+
27
+ def save_optimistic!(*args)
28
+ old_save!(*args)
29
+ rescue ActiveRecord::RecordNotUnique => e
30
+ errors.add('all', e.to_s)
31
+ raise ActiveRecord::RecordInvalid, self
32
+ end
33
+
21
34
  # def optimistic_unique
22
35
  # alias_method :save, :save_optimistic
23
36
  # end
@@ -28,6 +41,7 @@ ActiveSupport.on_load(:active_record) do
28
41
  def self.acts_as_unique
29
42
  include TPRecordOptimistic
30
43
  alias_method :save, :save_optimistic
44
+ alias_method :save!, :save_optimistic!
31
45
  end
32
46
  end
33
47
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tp_record_optimistic
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Fabricio Oliveira
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-03-14 00:00:00.000000000 Z
11
+ date: 2017-03-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails