lockless 0.2.0 → 0.2.1

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: b5cc6bb9658c48705098956a9caabc7c3f10cd99631dcd6b0fe776592f57cc9d
4
- data.tar.gz: 48d0dc5d8709224b6481e6d5b6316487c66b82b735a88a77d370d783bcaa62fd
3
+ metadata.gz: 51124ae3396a0a9df50cbe9a760f0af135ac3501f750ab200285cfc75a51b589
4
+ data.tar.gz: e7ea163317588600e6336fc3575867bd968b56c614f35083f1cefcb7f8ab5832
5
5
  SHA512:
6
- metadata.gz: a6580bfc5ac693248c355b82d6e6b9113c2772660ce0d7b2d9c31553a2da212d122cf0b757c93df78b7a985544f030b6bb66697e400f8857a749418a17ca16c0
7
- data.tar.gz: 3a6da4c0530cbe62a28831aec86966953cecf54433fac6ccd75070ff659b4febb1db2b1b5232f521476fca6595fc0a36402bcf4e3a42be9ba980e578e2e4cfb7
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 ignored the update
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"
@@ -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 model.method_defined?(:lockless_column) && updates[model.lockless_column].blank?
7
- updates[model.lockless_column] = model.generate_uuid
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)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Lockless
4
- VERSION = "0.2.0"
4
+ VERSION = "0.2.1"
5
5
  end
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.0
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-21 00:00:00.000000000 Z
11
+ date: 2021-11-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: standardrb