lockless 0.2.0 → 0.2.1
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.md +12 -1
- data/lib/lockless/relation.rb +11 -2
- data/lib/lockless/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 51124ae3396a0a9df50cbe9a760f0af135ac3501f750ab200285cfc75a51b589
|
4
|
+
data.tar.gz: e7ea163317588600e6336fc3575867bd968b56c614f35083f1cefcb7f8ab5832
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 93e1d8bd3e0e7807f085e0616f0e6dab260ef8870562479007d7fc655501cff6e321d49c69c233d865dd8981da4ae9ebfb6a92f1319eafc63647e0e311ea161c
|
7
|
+
data.tar.gz: 9a86ce69c0cc465a51956d71ad7e19e8930f465dddb31f4430e2112f28c060cafb479045f944efa14f4301e717e4c283ca79e91920330aabfcf4c265b6e75ec2
|
data/README.md
CHANGED
@@ -55,6 +55,15 @@ class AddLocklessUuidToUsers < ActiveRecord::Migration[5.0]
|
|
55
55
|
end
|
56
56
|
```
|
57
57
|
|
58
|
+
### Custom column name
|
59
|
+
|
60
|
+
```ruby
|
61
|
+
class User < ActiveRecord::Base
|
62
|
+
include Lockless::Model
|
63
|
+
self.lockless_column = :custom_uuid
|
64
|
+
end
|
65
|
+
```
|
66
|
+
|
58
67
|
### Sample Usage
|
59
68
|
|
60
69
|
```ruby
|
@@ -71,8 +80,10 @@ user2.lockless_save! # => true
|
|
71
80
|
# user1 fails to save as it's been updated earlier by user2
|
72
81
|
user1.lockless_save! # => false
|
73
82
|
|
74
|
-
# when lockless_save doesn't work you can either
|
83
|
+
# when lockless_save doesn't work you can either ignore the update and continue
|
75
84
|
# or reload the record and try again
|
85
|
+
# or calling `.save!` will forcefully save changes without respecting lockless
|
86
|
+
# `.save!` will cause the UUID to be changed again
|
76
87
|
|
77
88
|
user1.reload
|
78
89
|
user1.name # => "new name2"
|
data/lib/lockless/relation.rb
CHANGED
@@ -2,9 +2,18 @@
|
|
2
2
|
|
3
3
|
module Lockless
|
4
4
|
module Relation
|
5
|
+
# Appends update attributes with a random UUID when the model is a lockless model
|
6
|
+
#
|
7
|
+
# @param [String, Array, Hash] A string, array, or hash representing the SET part of an SQL statement.
|
8
|
+
# Lockless will only append random UUID updates if the param is a Hash
|
9
|
+
#
|
10
|
+
# @return [Boolean] Similar to `.save`, true is returned if the model is updated
|
11
|
+
# false is returned if record is outdated or invalid
|
5
12
|
def update_all(updates)
|
6
|
-
if
|
7
|
-
|
13
|
+
if updates.is_a?(Hash)
|
14
|
+
if model.method_defined?(:lockless_column) && updates[model.lockless_column].blank?
|
15
|
+
updates[model.lockless_column] = model.generate_uuid
|
16
|
+
end
|
8
17
|
end
|
9
18
|
|
10
19
|
super(updates)
|
data/lib/lockless/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lockless
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Cian McElhinney
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-11-
|
11
|
+
date: 2021-11-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: standardrb
|