mongoid-locking 0.1.2 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.tool-versions +1 -1
- data/Gemfile +1 -1
- data/Gemfile.lock +23 -19
- data/README.md +7 -0
- data/gemfiles/mongoid7.gemfile +1 -1
- data/lib/mongoid/locking/reloadable.rb +40 -0
- data/lib/mongoid/locking/selectable.rb +17 -5
- data/lib/mongoid/locking/version.rb +1 -1
- data/lib/mongoid/locking.rb +2 -0
- metadata +12 -12
- data/gemfiles/mongoid6.gemfile +0 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1be989a2d87d54412d3eafa95e4aeedb1bf9d0d97d5db712c5fdc190bc4f45ec
|
4
|
+
data.tar.gz: 8fea7cc8a65b2b331f7e692025e3cc0690a686024efb2d5e89528dc8205951cb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cac9e7692341645f57ab69863a724fac9773754f7f323bdf0e9c17cf311475a361d45c7495d1fc7db8e6784f71958b157d5f53edabde1dda6c1f569827955d40
|
7
|
+
data.tar.gz: ead4b76df6e9a5b8341bc8f842519f9545cea89ec6ffb00f25d4217881c16a757f85dfacc41f3fb1f571f501d831e7f959bef1c407d0a6be0312c7e74d6ee5c9
|
data/.tool-versions
CHANGED
@@ -1 +1 @@
|
|
1
|
-
ruby
|
1
|
+
ruby 3.1.4
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,33 +1,35 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
mongoid-locking (0.
|
5
|
-
mongoid (
|
4
|
+
mongoid-locking (1.0.0)
|
5
|
+
mongoid (~> 7.2.0)
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: https://rubygems.org/
|
9
9
|
specs:
|
10
|
-
activemodel (
|
11
|
-
activesupport (=
|
12
|
-
activesupport (
|
10
|
+
activemodel (6.1.7.6)
|
11
|
+
activesupport (= 6.1.7.6)
|
12
|
+
activesupport (6.1.7.6)
|
13
13
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
14
|
-
i18n (>=
|
15
|
-
minitest (
|
16
|
-
tzinfo (~>
|
14
|
+
i18n (>= 1.6, < 2)
|
15
|
+
minitest (>= 5.1)
|
16
|
+
tzinfo (~> 2.0)
|
17
|
+
zeitwerk (~> 2.3)
|
17
18
|
ast (2.4.2)
|
18
19
|
bson (4.15.0)
|
19
20
|
byebug (11.1.3)
|
20
|
-
concurrent-ruby (1.
|
21
|
+
concurrent-ruby (1.2.2)
|
21
22
|
diff-lcs (1.5.0)
|
22
|
-
i18n (1.
|
23
|
+
i18n (1.14.1)
|
23
24
|
concurrent-ruby (~> 1.0)
|
24
25
|
json (2.6.2)
|
25
|
-
minitest (5.
|
26
|
-
mongo (2.
|
26
|
+
minitest (5.20.0)
|
27
|
+
mongo (2.19.2)
|
27
28
|
bson (>= 4.14.1, < 5.0.0)
|
28
|
-
mongoid (
|
29
|
-
activemodel (>= 5.1, < 6.
|
30
|
-
mongo (>= 2.5
|
29
|
+
mongoid (7.2.6)
|
30
|
+
activemodel (>= 5.1, < 6.2)
|
31
|
+
mongo (>= 2.10.5, < 3.0.0)
|
32
|
+
ruby2_keywords (~> 0.0.5)
|
31
33
|
parallel (1.22.1)
|
32
34
|
parser (3.1.2.1)
|
33
35
|
ast (~> 2.4.1)
|
@@ -63,17 +65,19 @@ GEM
|
|
63
65
|
rubocop-rspec (2.12.1)
|
64
66
|
rubocop (~> 1.31)
|
65
67
|
ruby-progressbar (1.11.0)
|
66
|
-
|
67
|
-
tzinfo (
|
68
|
-
|
68
|
+
ruby2_keywords (0.0.5)
|
69
|
+
tzinfo (2.0.6)
|
70
|
+
concurrent-ruby (~> 1.0)
|
69
71
|
unicode-display_width (2.2.0)
|
72
|
+
zeitwerk (2.6.12)
|
70
73
|
|
71
74
|
PLATFORMS
|
72
75
|
arm64-darwin-21
|
76
|
+
arm64-darwin-22
|
73
77
|
|
74
78
|
DEPENDENCIES
|
75
79
|
byebug
|
76
|
-
mongoid (~>
|
80
|
+
mongoid (~> 7.2.0)
|
77
81
|
mongoid-locking!
|
78
82
|
rake (~> 13.0)
|
79
83
|
rspec
|
data/README.md
CHANGED
@@ -55,3 +55,10 @@ The gem is available as open source under the terms of the [MIT License](https:/
|
|
55
55
|
## Code of Conduct
|
56
56
|
|
57
57
|
Everyone interacting in the Mongoid::Locking project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/fullhealthmedical/fhweb/mongoid-locking/blob/master/CODE_OF_CONDUCT.md).
|
58
|
+
|
59
|
+
## Version Compability
|
60
|
+
|
61
|
+
| Gem version | Mongoid version | Ruby version |
|
62
|
+
| -------- | ------- | ------- |
|
63
|
+
| 0.1.2 | >= 6.0, < 7.2 | => 2.6 |
|
64
|
+
| 1.0.0 | ~> 7.2 | => 3.0 |
|
data/gemfiles/mongoid7.gemfile
CHANGED
@@ -0,0 +1,40 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
module Mongoid
|
3
|
+
module Locking
|
4
|
+
# This module handles reloading behaviour of documents.
|
5
|
+
#
|
6
|
+
# @since 4.0.0
|
7
|
+
module Reloadable
|
8
|
+
|
9
|
+
# Reloads the +Document+ attributes from the database. If the document has
|
10
|
+
# not been saved then an error will get raised if the configuration option
|
11
|
+
# was set. This can reload root documents or embedded documents.
|
12
|
+
#
|
13
|
+
# @example Reload the document.
|
14
|
+
# person.reload
|
15
|
+
#
|
16
|
+
# @raise [ Errors::DocumentNotFound ] If the document was deleted.
|
17
|
+
#
|
18
|
+
# @return [ Document ] The document, reloaded.
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
# Reload the root document.
|
23
|
+
#
|
24
|
+
# @example Reload the document.
|
25
|
+
# document.reload_root_document
|
26
|
+
#
|
27
|
+
# @return [ Hash ] The reloaded attributes.
|
28
|
+
#
|
29
|
+
# @since 2.3.2
|
30
|
+
# Starting from Mongoid version 7.2, the reload method now utilizes the
|
31
|
+
# `atomic_selector` to locate the current document.
|
32
|
+
#
|
33
|
+
# As the lock_version can be disregarded during a reload, this method
|
34
|
+
# has been overridden to bypass the lock version.
|
35
|
+
def reload_root_document
|
36
|
+
{}.merge(collection.find(atomic_selector(skip_lock_version: true)).read(mode: :primary).first || {})
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -5,13 +5,25 @@ module Mongoid
|
|
5
5
|
# its result.
|
6
6
|
#
|
7
7
|
# It is required when saving the same object multiple times in a row.
|
8
|
-
def atomic_selector
|
9
|
-
embedded? ? embedded_atomic_selector : root_atomic_selector
|
8
|
+
def atomic_selector(skip_lock_version: false)
|
9
|
+
embedded? ? embedded_atomic_selector : root_atomic_selector(skip_lock_version: skip_lock_version)
|
10
10
|
end
|
11
11
|
|
12
|
-
#
|
13
|
-
|
14
|
-
|
12
|
+
# Get the atomic selector for a root document.
|
13
|
+
#
|
14
|
+
# @api private
|
15
|
+
#
|
16
|
+
# @example Get the root atomic selector.
|
17
|
+
# document.root_atomic_selector
|
18
|
+
#
|
19
|
+
# @return [ Hash ] The root document selector.
|
20
|
+
#
|
21
|
+
# @since 4.0.0
|
22
|
+
# https://github.com/mongodb/mongoid/blob/7.2-stable/lib/mongoid/selectable.rb#L57
|
23
|
+
def root_atomic_selector(skip_lock_version: false)
|
24
|
+
return { "_id" => id, "lock_version" => lock_version }.merge!(shard_key_selector) unless skip_lock_version
|
25
|
+
|
26
|
+
{ "_id" => id }.merge!(shard_key_selector)
|
15
27
|
end
|
16
28
|
end
|
17
29
|
end
|
data/lib/mongoid/locking.rb
CHANGED
@@ -4,6 +4,7 @@ require_relative "stale_object_error"
|
|
4
4
|
require_relative "locking/contextual/atomic"
|
5
5
|
require_relative "locking/contextual/mongo"
|
6
6
|
require_relative "locking/selectable"
|
7
|
+
require_relative "locking/reloadable"
|
7
8
|
require_relative "locking/persistable/creatable"
|
8
9
|
require_relative "locking/persistable/updatable"
|
9
10
|
require_relative "locking/persistable"
|
@@ -19,6 +20,7 @@ module Mongoid
|
|
19
20
|
base.before_create { self.lock_version = 0 }
|
20
21
|
|
21
22
|
base.include Mongoid::Locking::Selectable
|
23
|
+
base.include Mongoid::Locking::Reloadable
|
22
24
|
# base.include Mongoid::Locking::Reloadable if Mongoid::VERSION >= "7"
|
23
25
|
end
|
24
26
|
end
|
metadata
CHANGED
@@ -1,29 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mongoid-locking
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rodrigo RA
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-11-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mongoid
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 7.2.0
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 7.2.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: byebug
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -111,7 +111,6 @@ files:
|
|
111
111
|
- LICENSE.txt
|
112
112
|
- README.md
|
113
113
|
- Rakefile
|
114
|
-
- gemfiles/mongoid6.gemfile
|
115
114
|
- gemfiles/mongoid7.gemfile
|
116
115
|
- lib/mongoid/locking.rb
|
117
116
|
- lib/mongoid/locking/contextual/atomic.rb
|
@@ -119,6 +118,7 @@ files:
|
|
119
118
|
- lib/mongoid/locking/persistable.rb
|
120
119
|
- lib/mongoid/locking/persistable/creatable.rb
|
121
120
|
- lib/mongoid/locking/persistable/updatable.rb
|
121
|
+
- lib/mongoid/locking/reloadable.rb
|
122
122
|
- lib/mongoid/locking/selectable.rb
|
123
123
|
- lib/mongoid/locking/version.rb
|
124
124
|
- lib/mongoid/stale_object_error.rb
|
@@ -131,7 +131,7 @@ metadata:
|
|
131
131
|
homepage_uri: https://github.com/fullhealthmedical/mongoid-locking
|
132
132
|
source_code_uri: https://github.com/fullhealthmedical/mongoid-locking
|
133
133
|
changelog_uri: https://github.com/fullhealthmedical/blob/main/CHANGELOG.md
|
134
|
-
post_install_message:
|
134
|
+
post_install_message:
|
135
135
|
rdoc_options: []
|
136
136
|
require_paths:
|
137
137
|
- lib
|
@@ -139,15 +139,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
139
139
|
requirements:
|
140
140
|
- - ">="
|
141
141
|
- !ruby/object:Gem::Version
|
142
|
-
version:
|
142
|
+
version: 3.0.0
|
143
143
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
144
144
|
requirements:
|
145
145
|
- - ">="
|
146
146
|
- !ruby/object:Gem::Version
|
147
147
|
version: '0'
|
148
148
|
requirements: []
|
149
|
-
rubygems_version: 3.
|
150
|
-
signing_key:
|
149
|
+
rubygems_version: 3.3.26
|
150
|
+
signing_key:
|
151
151
|
specification_version: 4
|
152
152
|
summary: Implements optimistic locking for Mongoid objects.
|
153
153
|
test_files: []
|