mongoid-locking 0.1.2 → 1.1.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
  SHA256:
3
- metadata.gz: f2c6191141885a2f6a15d09a8ab111240dc9fea9a3f7a88328204606fdea66ec
4
- data.tar.gz: fa595b089cda173fdcc4c2597f027d8db904aa79db716d269e64db8aaf99d240
3
+ metadata.gz: d6150316b83b781d4f26eff62a82a593aff8f7a7a81791ae7b003801e9cc2f44
4
+ data.tar.gz: 57a84b81757d94e4d4bfaceaea0f98f8437bd61bf7832be9e030fcb37fd5146c
5
5
  SHA512:
6
- metadata.gz: 40608a2e608a2200346b7aa83a983dbe91339d68403e60c5271ab71bb5740d5828028f13ae60898a9d858de4a0735fc2e500f158f272216946b92b35c58490bb
7
- data.tar.gz: 1a2a8ae267745644d35b755c99ad820f7ecbc69df4c468fc851efaac76ba589085a62a2085da2be56160077fdcfcfc010601d88cb51d19a97585b4b6bfade44c
6
+ metadata.gz: 743b07e99b92af64d0d209580f2a5851c44800a51c7c33e794cc655661abfeb86c65e1f8df66cd7eb42197466020cae038c85dd9dfd2656b7e187204cddcd3a1
7
+ data.tar.gz: c14fb5d640c3bf4b6a4edfab3929aae1244a13f62ebe40641bd5a7a354357203f8f7e8add1e396ca07917d57cc3f4fd9af3ea3f3b5d589c3ceef17fa595de043
data/.tool-versions CHANGED
@@ -1 +1 @@
1
- ruby 2.6.7
1
+ ruby 3.1.4
data/Gemfile CHANGED
@@ -5,4 +5,4 @@ source "https://rubygems.org"
5
5
  # Specify your gem's dependencies in mongoid-locking.gemspec
6
6
  gemspec
7
7
 
8
- gem "mongoid", "~> 6.0"
8
+ gem "mongoid", "~> 7.2"
data/Gemfile.lock CHANGED
@@ -1,33 +1,35 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- mongoid-locking (0.1.2)
5
- mongoid (> 6.0)
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 (5.2.8.1)
11
- activesupport (= 5.2.8.1)
12
- activesupport (5.2.8.1)
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 (>= 0.7, < 2)
15
- minitest (~> 5.1)
16
- tzinfo (~> 1.1)
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.1.10)
21
+ concurrent-ruby (1.2.2)
21
22
  diff-lcs (1.5.0)
22
- i18n (1.12.0)
23
+ i18n (1.14.1)
23
24
  concurrent-ruby (~> 1.0)
24
25
  json (2.6.2)
25
- minitest (5.16.3)
26
- mongo (2.18.1)
26
+ minitest (5.20.0)
27
+ mongo (2.19.2)
27
28
  bson (>= 4.14.1, < 5.0.0)
28
- mongoid (6.4.8)
29
- activemodel (>= 5.1, < 6.0.0)
30
- mongo (>= 2.5.1, < 3.0.0)
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
- thread_safe (0.3.6)
67
- tzinfo (1.2.10)
68
- thread_safe (~> 0.1)
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 (~> 6.0)
80
+ mongoid (~> 7.2.0)
77
81
  mongoid-locking!
78
82
  rake (~> 13.0)
79
83
  rspec
data/README.md CHANGED
@@ -55,3 +55,11 @@ 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 |
62
+ | -------- | ------- |
63
+ | 0.1.2 | >= 6.0, < 7.2 |
64
+ | 1.0.0 | ~> 7.2.0 |
65
+ | 1.1.0 | ~> 7.2 |
@@ -3,4 +3,4 @@ source "https://rubygems.org"
3
3
  # Specify your gem's dependencies in mongoid-locking.gemspec
4
4
  gemspec path: ".."
5
5
 
6
- gem "mongoid", "~> 6.0"
6
+ gem "mongoid", "~> 7.2.0"
@@ -3,4 +3,4 @@ source "https://rubygems.org"
3
3
  # Specify your gem's dependencies in mongoid-locking.gemspec
4
4
  gemspec path: ".."
5
5
 
6
- gem "mongoid", "~> 7.0"
6
+ gem "mongoid", "~> 7.3.0"
@@ -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
- # https://github.com/mongodb/mongoid/blob/e03120a56894bc773dcf1e51209eb2f3e6f2b61f/lib/mongoid/selectable.rb#L55
13
- def root_atomic_selector
14
- { "_id" => id, "lock_version" => lock_version }
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
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Mongoid
4
4
  module Locking
5
- VERSION = "0.1.2"
5
+ VERSION = "1.1.0"
6
6
  end
7
7
  end
@@ -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.1.2
4
+ version: 1.1.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: 2022-09-05 00:00:00.000000000 Z
11
+ date: 2023-11-17 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: '6.0'
19
+ version: '7.2'
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: '6.0'
26
+ version: '7.2'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: byebug
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -111,14 +111,15 @@ files:
111
111
  - LICENSE.txt
112
112
  - README.md
113
113
  - Rakefile
114
- - gemfiles/mongoid6.gemfile
115
- - gemfiles/mongoid7.gemfile
114
+ - gemfiles/mongoid7_2.gemfile
115
+ - gemfiles/mongoid7_3.gemfile
116
116
  - lib/mongoid/locking.rb
117
117
  - lib/mongoid/locking/contextual/atomic.rb
118
118
  - lib/mongoid/locking/contextual/mongo.rb
119
119
  - lib/mongoid/locking/persistable.rb
120
120
  - lib/mongoid/locking/persistable/creatable.rb
121
121
  - lib/mongoid/locking/persistable/updatable.rb
122
+ - lib/mongoid/locking/reloadable.rb
122
123
  - lib/mongoid/locking/selectable.rb
123
124
  - lib/mongoid/locking/version.rb
124
125
  - lib/mongoid/stale_object_error.rb
@@ -131,7 +132,7 @@ metadata:
131
132
  homepage_uri: https://github.com/fullhealthmedical/mongoid-locking
132
133
  source_code_uri: https://github.com/fullhealthmedical/mongoid-locking
133
134
  changelog_uri: https://github.com/fullhealthmedical/blob/main/CHANGELOG.md
134
- post_install_message:
135
+ post_install_message:
135
136
  rdoc_options: []
136
137
  require_paths:
137
138
  - lib
@@ -139,15 +140,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
139
140
  requirements:
140
141
  - - ">="
141
142
  - !ruby/object:Gem::Version
142
- version: 2.6.0
143
+ version: 3.0.0
143
144
  required_rubygems_version: !ruby/object:Gem::Requirement
144
145
  requirements:
145
146
  - - ">="
146
147
  - !ruby/object:Gem::Version
147
148
  version: '0'
148
149
  requirements: []
149
- rubygems_version: 3.0.3.1
150
- signing_key:
150
+ rubygems_version: 3.3.26
151
+ signing_key:
151
152
  specification_version: 4
152
153
  summary: Implements optimistic locking for Mongoid objects.
153
154
  test_files: []