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 +4 -4
- data/README.rdoc +18 -1
- data/lib/tp_record_optimistic/version.rb +1 -1
- data/lib/tp_record_optimistic.rb +14 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 18b8156926d15c46a8ffdc916f1b093cf50c9aeb
|
4
|
+
data.tar.gz: 46322a6464c78088d2aff604926e12d7307f6f7e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8e76fbe00a06098a7117b18dc78b1119cbe37ba50baa8ae706e2baf498db5ff958aa6876ad8dcb19c9e1527fa483168afca19f9bebc34308ad5c0618793a4abd
|
7
|
+
data.tar.gz: e10d80cad8300d6e21836d4ab1b9288cc05bc6b6fe18358749322db748b0bb2953c1f42239ac04b6b7f33545e04c448d3987bd2af0207a9311db02512ac05be3
|
data/README.rdoc
CHANGED
@@ -1,3 +1,20 @@
|
|
1
1
|
= TPOptimistic
|
2
2
|
|
3
|
-
|
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
|
data/lib/tp_record_optimistic.rb
CHANGED
@@ -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.
|
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-
|
11
|
+
date: 2017-03-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|