mongoid_orderable 6.0.4 → 6.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +9 -3
- data/lib/mongoid/orderable/configs/field_config.rb +1 -1
- data/lib/mongoid/orderable/generators/base.rb +1 -1
- data/lib/mongoid/orderable/generators/listable.rb +1 -1
- data/lib/mongoid/orderable/generators/lock_collection.rb +1 -1
- data/lib/mongoid/orderable/generators/movable.rb +1 -1
- data/lib/mongoid/orderable/generators/position.rb +3 -3
- data/lib/mongoid/orderable/generators/scope.rb +1 -1
- data/lib/mongoid/orderable/handlers/base.rb +32 -6
- data/lib/mongoid/orderable/handlers/document.rb +9 -1
- data/lib/mongoid/orderable/handlers/document_transactional.rb +3 -6
- data/lib/mongoid/orderable/handlers/transaction.rb +6 -2
- data/lib/mongoid/orderable/installer.rb +1 -1
- data/lib/mongoid/orderable/mixins/callbacks.rb +3 -1
- data/lib/mongoid/orderable/mixins/movable.rb +7 -3
- data/lib/mongoid/orderable/version.rb +1 -1
- data/lib/mongoid_orderable.rb +1 -2
- metadata +5 -92
- data/spec/integration/cascadeable_spec.rb +0 -12
- data/spec/integration/concurrency_spec.rb +0 -232
- data/spec/integration/conditional_spec.rb +0 -36
- data/spec/integration/customized_spec.rb +0 -31
- data/spec/integration/embedded_spec.rb +0 -63
- data/spec/integration/foreign_key_spec.rb +0 -33
- data/spec/integration/inherited_spec.rb +0 -54
- data/spec/integration/multiple_fields_spec.rb +0 -554
- data/spec/integration/multiple_scoped_spec.rb +0 -63
- data/spec/integration/no_indexed_spec.rb +0 -23
- data/spec/integration/scoped_spec.rb +0 -151
- data/spec/integration/simple_spec.rb +0 -184
- data/spec/integration/string_scoped_spec.rb +0 -28
- data/spec/integration/zero_based_spec.rb +0 -161
- data/spec/spec_helper.rb +0 -42
- data/spec/support/models.rb +0 -134
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 130b0033ba55283b4cb619832e51b4b9c42191db02c12e0b9db87e98fb3c6cb8
|
4
|
+
data.tar.gz: 24994768318208173add72989cf364c888137a739390d39f9759d35fbb8a2ce6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e401433fc0247621f99cebad69db3034f8b525a3d93035b8ec07c4deeb1116a5a1d568504e0ccfaeb23b8fe9f8fdd56ba5ef41add3526ed4e020b8a8b79f53ec
|
7
|
+
data.tar.gz: 73c6c58d8a9da7e14a2e6f9f0866fbf3a7bedf194f81b44d9156387f57c4032f3fb2a04c8fe94dd49953d259b59c0f9f49c9f37778f3c773a3e61a9705965bbb
|
data/CHANGELOG.md
CHANGED
@@ -1,8 +1,14 @@
|
|
1
|
-
### 6.0.
|
1
|
+
### 6.0.6 (Next)
|
2
2
|
|
3
|
-
* Your
|
3
|
+
* Your change here.
|
4
4
|
|
5
|
-
### 6.0.
|
5
|
+
### 6.0.5 (2023/11/08)
|
6
|
+
|
7
|
+
* [#75](https://github.com/mongoid/mongoid_orderable/pull/75): Fix: Preserve position when creating new records.
|
8
|
+
* [#84](https://github.com/mongoid/mongoid_orderable/pull/84): Feature: Use Mongo::QueryCache if available.
|
9
|
+
* [#85](https://github.com/mongoid/mongoid_orderable/pull/85): Refactor: Replace all usages of "protected" with "private".
|
10
|
+
|
11
|
+
### 6.0.4 (2023/02/01)
|
6
12
|
|
7
13
|
* [#75](https://github.com/mongoid/mongoid_orderable/pull/75): Fix: Setting #move_to should mark an orderable object as changed so that callbacks are triggered.
|
8
14
|
|
@@ -8,16 +8,16 @@ module Generators
|
|
8
8
|
klass.class_eval <<~KLASS, __FILE__, __LINE__ + 1
|
9
9
|
def orderable_position(field = nil)
|
10
10
|
field ||= default_orderable_field
|
11
|
-
send
|
11
|
+
send("orderable_\#{field}_position")
|
12
12
|
end
|
13
13
|
KLASS
|
14
14
|
|
15
15
|
generate_method("orderable_#{field_name}_position") do
|
16
|
-
send
|
16
|
+
send(field_name)
|
17
17
|
end
|
18
18
|
|
19
19
|
generate_method("orderable_#{field_name}_position=") do |value|
|
20
|
-
send
|
20
|
+
send("#{field_name}=", value)
|
21
21
|
end
|
22
22
|
end
|
23
23
|
end
|
@@ -8,9 +8,10 @@ module Handlers
|
|
8
8
|
|
9
9
|
def initialize(doc)
|
10
10
|
@doc = doc
|
11
|
+
reset_new_record
|
11
12
|
end
|
12
13
|
|
13
|
-
|
14
|
+
private
|
14
15
|
|
15
16
|
delegate :orderable_keys,
|
16
17
|
:orderable_field,
|
@@ -22,12 +23,15 @@ module Handlers
|
|
22
23
|
:orderable_top,
|
23
24
|
:orderable_bottom,
|
24
25
|
:_id,
|
25
|
-
:new_record?,
|
26
26
|
:persisted?,
|
27
27
|
:embedded?,
|
28
28
|
:collection_name,
|
29
29
|
to: :doc
|
30
30
|
|
31
|
+
def new_record?
|
32
|
+
use_transactions ? @new_record : doc.new_record?
|
33
|
+
end
|
34
|
+
|
31
35
|
def use_transactions
|
32
36
|
false
|
33
37
|
end
|
@@ -36,8 +40,18 @@ module Handlers
|
|
36
40
|
orderable_keys.any? {|field| changed?(field) }
|
37
41
|
end
|
38
42
|
|
43
|
+
def set_new_record_positions
|
44
|
+
return unless new_record?
|
45
|
+
|
46
|
+
orderable_keys.each do |field|
|
47
|
+
next unless (position = doc.send(field))
|
48
|
+
|
49
|
+
move_all[field] ||= position
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
39
53
|
def apply_all_positions
|
40
|
-
orderable_keys.
|
54
|
+
orderable_keys.each {|field| apply_one_position(field, move_all[field]) }
|
41
55
|
end
|
42
56
|
|
43
57
|
def apply_one_position(field, target_position)
|
@@ -56,7 +70,7 @@ module Handlers
|
|
56
70
|
end
|
57
71
|
|
58
72
|
# Get the current position as exists in the database
|
59
|
-
current = if
|
73
|
+
current = if new_record? || scope_changed
|
60
74
|
nil
|
61
75
|
elsif persisted? && !embedded?
|
62
76
|
scope.where(_id: _id).pluck(f).first
|
@@ -74,8 +88,9 @@ module Handlers
|
|
74
88
|
in_list = persisted? && current
|
75
89
|
return if in_list && !target_position
|
76
90
|
|
77
|
-
# Use $inc operator to shift the position of the other documents
|
78
91
|
target = resolve_target_position(field, target_position, in_list)
|
92
|
+
|
93
|
+
# Use $inc operator to shift the position of the other documents
|
79
94
|
if !in_list
|
80
95
|
scope.gte(f => target).inc(f => 1)
|
81
96
|
elsif target < current
|
@@ -107,10 +122,21 @@ module Handlers
|
|
107
122
|
doc.send(:move_all)
|
108
123
|
end
|
109
124
|
|
125
|
+
def reset
|
126
|
+
reset_new_record
|
127
|
+
doc.send(:clear_move_all!)
|
128
|
+
end
|
129
|
+
|
130
|
+
# Required for transactions, which perform some actions
|
131
|
+
# in the after_create callback.
|
132
|
+
def reset_new_record
|
133
|
+
@new_record = doc.new_record?
|
134
|
+
end
|
135
|
+
|
110
136
|
def resolve_target_position(field, target_position, in_list)
|
111
137
|
target_position ||= 'bottom'
|
112
138
|
|
113
|
-
unless target_position.is_a?
|
139
|
+
unless target_position.is_a?(Numeric)
|
114
140
|
target_position = case target_position.to_s
|
115
141
|
when 'top' then (min ||= orderable_top(field))
|
116
142
|
when 'bottom' then (max ||= orderable_bottom(field, in_list))
|
@@ -5,18 +5,26 @@ module Orderable
|
|
5
5
|
module Handlers
|
6
6
|
class Document < Base
|
7
7
|
def before_create
|
8
|
+
set_new_record_positions
|
8
9
|
apply_all_positions
|
9
10
|
end
|
10
11
|
|
11
|
-
def after_create
|
12
|
+
def after_create
|
13
|
+
reset
|
14
|
+
end
|
12
15
|
|
13
16
|
def before_update
|
14
17
|
return unless any_field_changed?
|
15
18
|
apply_all_positions
|
16
19
|
end
|
17
20
|
|
21
|
+
def after_update
|
22
|
+
reset
|
23
|
+
end
|
24
|
+
|
18
25
|
def after_destroy
|
19
26
|
remove_all_positions
|
27
|
+
reset
|
20
28
|
end
|
21
29
|
end
|
22
30
|
end
|
@@ -5,23 +5,20 @@ module Orderable
|
|
5
5
|
module Handlers
|
6
6
|
class DocumentTransactional < Document
|
7
7
|
def before_create
|
8
|
-
|
8
|
+
set_new_record_positions
|
9
9
|
end
|
10
10
|
|
11
11
|
def after_create
|
12
12
|
apply_all_positions
|
13
|
+
super
|
13
14
|
end
|
14
15
|
|
15
|
-
|
16
|
+
private
|
16
17
|
|
17
18
|
def apply_all_positions
|
18
19
|
with_transaction { super }
|
19
20
|
end
|
20
21
|
|
21
|
-
def clear_all_positions
|
22
|
-
orderable_keys.each {|field| doc.send("orderable_#{field}_position=", nil) }
|
23
|
-
end
|
24
|
-
|
25
22
|
def use_transactions
|
26
23
|
true
|
27
24
|
end
|
@@ -15,7 +15,7 @@ module Handlers
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def with_transaction(&block)
|
18
|
-
|
18
|
+
query_cache.uncached do
|
19
19
|
if Thread.current[THREAD_KEY]
|
20
20
|
yield
|
21
21
|
else
|
@@ -35,7 +35,7 @@ module Handlers
|
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
38
|
-
|
38
|
+
private
|
39
39
|
|
40
40
|
def do_transaction(&_block)
|
41
41
|
doc.class.with_session(session_opts) do |session|
|
@@ -65,6 +65,10 @@ module Handlers
|
|
65
65
|
def transaction_max_retries
|
66
66
|
doc.orderable_keys.map {|k| doc.class.orderable_configs.dig(k, :transaction_max_retries) }.compact.max
|
67
67
|
end
|
68
|
+
|
69
|
+
def query_cache
|
70
|
+
defined?(Mongo::QueryCache) ? Mongo::QueryCache : Mongoid::QueryCache
|
71
|
+
end
|
68
72
|
end
|
69
73
|
end
|
70
74
|
end
|
@@ -12,16 +12,18 @@ module Mixins
|
|
12
12
|
before_create :orderable_before_create
|
13
13
|
after_create :orderable_after_create, prepend: true
|
14
14
|
before_update :orderable_before_update
|
15
|
+
after_update :orderable_after_update, prepend: true
|
15
16
|
after_destroy :orderable_after_destroy, prepend: true
|
16
17
|
|
17
18
|
delegate :before_create,
|
18
19
|
:after_create,
|
19
20
|
:before_update,
|
21
|
+
:after_update,
|
20
22
|
:after_destroy,
|
21
23
|
to: :orderable_handler,
|
22
24
|
prefix: :orderable
|
23
25
|
|
24
|
-
|
26
|
+
private
|
25
27
|
|
26
28
|
def orderable_handler
|
27
29
|
@orderable_handler ||= self.class.orderable_handler_class.new(self)
|
@@ -44,15 +44,19 @@ module Mixins
|
|
44
44
|
KLASS
|
45
45
|
end
|
46
46
|
|
47
|
-
|
47
|
+
private
|
48
48
|
|
49
49
|
def move_all
|
50
|
-
@move_all
|
50
|
+
@move_all ||= {}
|
51
51
|
end
|
52
52
|
|
53
53
|
def move_field_to(position, options)
|
54
54
|
field = options[:field] || default_orderable_field
|
55
|
-
|
55
|
+
move_all[field] = position
|
56
|
+
end
|
57
|
+
|
58
|
+
def clear_move_all!
|
59
|
+
@move_all = {}
|
56
60
|
end
|
57
61
|
end
|
58
62
|
end
|
data/lib/mongoid_orderable.rb
CHANGED
@@ -7,9 +7,8 @@ I18n.load_path << File.join(File.dirname(__FILE__), 'config', 'locales', 'en.yml
|
|
7
7
|
|
8
8
|
require 'mongoid'
|
9
9
|
|
10
|
-
require 'mongoid/orderable/version'
|
11
|
-
|
12
10
|
require 'mongoid/orderable'
|
11
|
+
require 'mongoid/orderable/version'
|
13
12
|
require 'mongoid/orderable/configs/global_config'
|
14
13
|
require 'mongoid/orderable/configs/field_config'
|
15
14
|
require 'mongoid/orderable/errors/invalid_target_position'
|
metadata
CHANGED
@@ -1,71 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mongoid_orderable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 6.0.
|
4
|
+
version: 6.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- pyromaniac
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-11-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
-
- !ruby/object:Gem::Dependency
|
14
|
-
name: rake
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - ">="
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: '0'
|
20
|
-
type: :development
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - ">="
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: '0'
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: rspec
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - ">="
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: 3.0.0
|
34
|
-
type: :development
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - ">="
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: 3.0.0
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
name: rspec-retry
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
44
|
-
requirements:
|
45
|
-
- - ">="
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: '0'
|
48
|
-
type: :development
|
49
|
-
prerelease: false
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
51
|
-
requirements:
|
52
|
-
- - ">="
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: '0'
|
55
|
-
- !ruby/object:Gem::Dependency
|
56
|
-
name: rubocop
|
57
|
-
requirement: !ruby/object:Gem::Requirement
|
58
|
-
requirements:
|
59
|
-
- - ">="
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: 1.8.1
|
62
|
-
type: :development
|
63
|
-
prerelease: false
|
64
|
-
version_requirements: !ruby/object:Gem::Requirement
|
65
|
-
requirements:
|
66
|
-
- - ">="
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
version: 1.8.1
|
69
13
|
- !ruby/object:Gem::Dependency
|
70
14
|
name: mongoid
|
71
15
|
requirement: !ruby/object:Gem::Requirement
|
@@ -117,26 +61,11 @@ files:
|
|
117
61
|
- lib/mongoid/orderable/mixins/movable.rb
|
118
62
|
- lib/mongoid/orderable/version.rb
|
119
63
|
- lib/mongoid_orderable.rb
|
120
|
-
- spec/integration/cascadeable_spec.rb
|
121
|
-
- spec/integration/concurrency_spec.rb
|
122
|
-
- spec/integration/conditional_spec.rb
|
123
|
-
- spec/integration/customized_spec.rb
|
124
|
-
- spec/integration/embedded_spec.rb
|
125
|
-
- spec/integration/foreign_key_spec.rb
|
126
|
-
- spec/integration/inherited_spec.rb
|
127
|
-
- spec/integration/multiple_fields_spec.rb
|
128
|
-
- spec/integration/multiple_scoped_spec.rb
|
129
|
-
- spec/integration/no_indexed_spec.rb
|
130
|
-
- spec/integration/scoped_spec.rb
|
131
|
-
- spec/integration/simple_spec.rb
|
132
|
-
- spec/integration/string_scoped_spec.rb
|
133
|
-
- spec/integration/zero_based_spec.rb
|
134
|
-
- spec/spec_helper.rb
|
135
|
-
- spec/support/models.rb
|
136
64
|
homepage: https://github.com/mongoid/mongoid_orderable
|
137
65
|
licenses:
|
138
66
|
- MIT
|
139
|
-
metadata:
|
67
|
+
metadata:
|
68
|
+
rubygems_mfa_required: 'true'
|
140
69
|
post_install_message:
|
141
70
|
rdoc_options: []
|
142
71
|
require_paths:
|
@@ -156,20 +85,4 @@ rubygems_version: 3.4.4
|
|
156
85
|
signing_key:
|
157
86
|
specification_version: 4
|
158
87
|
summary: Mongoid orderable list implementation
|
159
|
-
test_files:
|
160
|
-
- spec/integration/cascadeable_spec.rb
|
161
|
-
- spec/integration/concurrency_spec.rb
|
162
|
-
- spec/integration/conditional_spec.rb
|
163
|
-
- spec/integration/customized_spec.rb
|
164
|
-
- spec/integration/embedded_spec.rb
|
165
|
-
- spec/integration/foreign_key_spec.rb
|
166
|
-
- spec/integration/inherited_spec.rb
|
167
|
-
- spec/integration/multiple_fields_spec.rb
|
168
|
-
- spec/integration/multiple_scoped_spec.rb
|
169
|
-
- spec/integration/no_indexed_spec.rb
|
170
|
-
- spec/integration/scoped_spec.rb
|
171
|
-
- spec/integration/simple_spec.rb
|
172
|
-
- spec/integration/string_scoped_spec.rb
|
173
|
-
- spec/integration/zero_based_spec.rb
|
174
|
-
- spec/spec_helper.rb
|
175
|
-
- spec/support/models.rb
|
88
|
+
test_files: []
|
@@ -1,12 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Mongoid::Orderable::Mixins::Cascadeable do
|
4
|
-
|
5
|
-
it do
|
6
|
-
eo = EmbedsOrderable.create!
|
7
|
-
orderable = eo.embedded_orderables.create!
|
8
|
-
expect(orderable.in_callback_state?(:update)).to eq false
|
9
|
-
orderable.move_to = 2
|
10
|
-
expect(orderable.in_callback_state?(:update)).to eq true
|
11
|
-
end
|
12
|
-
end
|