positioning 0.1.2 → 0.1.3
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/CHANGELOG.md +6 -0
- data/Gemfile +5 -0
- data/lib/positioning/mechanisms.rb +25 -15
- data/lib/positioning/version.rb +1 -1
- metadata +2 -3
- data/Gemfile.lock +0 -109
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 20e2658aa131e9c641fc3b5bdd2f685d64af56d56a53abb0eef4a25f12b4f293
|
4
|
+
data.tar.gz: 61d5b5e9afb5ad0d037ccb2a14185dfe0fca705cb0850f89e436d1e371608d9f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 51c9fa527fea19618a9b5362cc81cce367dfa15039328a3085598fd1c5ea8e2f6b8bcf92b650c82d83fb0e221ef307b893580a4172fb0f3c94200a8cdb1579c4
|
7
|
+
data.tar.gz: 8ca5d909229d1c2d8f1712c5ca21275ac75f733de7bf799c7c3d8777f609116efa6127b7a657d09e6a5396769c5451a8a44218941e15d836abaa3b99e954bef3
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,11 @@
|
|
1
1
|
## [Unreleased]
|
2
2
|
|
3
|
+
## [0.1.3] - 2024-03-04
|
4
|
+
|
5
|
+
- Internal refactoring of Mechanisms for clarity
|
6
|
+
- Additional unit testing of Mechanisms
|
7
|
+
- Added additional Ruby and Rails versions to the Github Actions matrix
|
8
|
+
|
3
9
|
## [0.1.2] - 2024-02-29
|
4
10
|
|
5
11
|
- Fix a bug related to the scope changing with an explicitly set position value that is the same as the original position.
|
data/Gemfile
CHANGED
@@ -20,23 +20,14 @@ module Positioning
|
|
20
20
|
end
|
21
21
|
|
22
22
|
def update_position
|
23
|
-
|
24
|
-
# to nil so that the item gets placed at the end of the list.
|
25
|
-
self.position = nil if positioning_scope_changed? && !position_changed?
|
23
|
+
clear_position if positioning_scope_changed? && !position_changed?
|
26
24
|
|
27
25
|
solidify_position
|
28
26
|
|
29
|
-
# The update strategy is to temporarily set our position to 0, then shift everything out of the way of
|
30
|
-
# our new desired position before finalising it.
|
31
27
|
if positioning_scope_changed? || position_changed?
|
32
|
-
|
33
|
-
|
34
|
-
position_was = record_scope.pick(@column)
|
35
|
-
record_scope.update_all "#{@column}": 0
|
28
|
+
move_out_of_the_way
|
36
29
|
|
37
30
|
if positioning_scope_changed?
|
38
|
-
positioning_scope_was = base_class.where record_scope.first.slice(*positioning_columns)
|
39
|
-
|
40
31
|
contract(positioning_scope_was, position_was..)
|
41
32
|
expand(positioning_scope, position..)
|
42
33
|
elsif position_was > position
|
@@ -65,6 +56,10 @@ module Positioning
|
|
65
56
|
@positioned.send primary_key_column
|
66
57
|
end
|
67
58
|
|
59
|
+
def record_scope
|
60
|
+
base_class.where("#{primary_key_column}": primary_key)
|
61
|
+
end
|
62
|
+
|
68
63
|
def position
|
69
64
|
@positioned.send @column
|
70
65
|
end
|
@@ -73,10 +68,23 @@ module Positioning
|
|
73
68
|
@positioned.send :"#{@column}=", position
|
74
69
|
end
|
75
70
|
|
71
|
+
def clear_position
|
72
|
+
self.position = nil
|
73
|
+
end
|
74
|
+
|
76
75
|
def position_changed?
|
77
76
|
@positioned.send :"#{@column}_changed?"
|
78
77
|
end
|
79
78
|
|
79
|
+
def position_was
|
80
|
+
@position_was ||= record_scope.pick(@column)
|
81
|
+
end
|
82
|
+
|
83
|
+
def move_out_of_the_way
|
84
|
+
position_was # Memoize the original position before changing it
|
85
|
+
record_scope.update_all "#{@column}": 0
|
86
|
+
end
|
87
|
+
|
80
88
|
def expand(scope, range)
|
81
89
|
scope.where("#{@column}": range).update_all "#{@column} = #{@column} * -1"
|
82
90
|
scope.where("#{@column}": ..-1).update_all "#{@column} = #{@column} * -1 + 1"
|
@@ -118,8 +126,6 @@ module Positioning
|
|
118
126
|
raise Error.new, "relative `#{@column}` record must be in the same scope"
|
119
127
|
end
|
120
128
|
|
121
|
-
position_was = base_class.where("#{primary_key_column}": primary_key).pick(@column)
|
122
|
-
|
123
129
|
solidified_position = relative_record_scope.pick(@column)
|
124
130
|
solidified_position += 1 if relative_position == :after
|
125
131
|
solidified_position -= 1 if in_positioning_scope? && position_was < solidified_position
|
@@ -143,11 +149,15 @@ module Positioning
|
|
143
149
|
end
|
144
150
|
|
145
151
|
def positioning_scope
|
146
|
-
base_class.where
|
152
|
+
base_class.where @positioned.slice(*positioning_columns)
|
153
|
+
end
|
154
|
+
|
155
|
+
def positioning_scope_was
|
156
|
+
base_class.where record_scope.first.slice(*positioning_columns)
|
147
157
|
end
|
148
158
|
|
149
159
|
def in_positioning_scope?
|
150
|
-
@positioned.persisted? && positioning_scope.
|
160
|
+
@positioned.persisted? && positioning_scope.where("#{primary_key_column}": primary_key).exists?
|
151
161
|
end
|
152
162
|
|
153
163
|
def positioning_scope_changed?
|
data/lib/positioning/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: positioning
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brendon Muir
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-03-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -118,7 +118,6 @@ files:
|
|
118
118
|
- ".standard.yml"
|
119
119
|
- CHANGELOG.md
|
120
120
|
- Gemfile
|
121
|
-
- Gemfile.lock
|
122
121
|
- LICENSE.txt
|
123
122
|
- README.md
|
124
123
|
- Rakefile
|
data/Gemfile.lock
DELETED
@@ -1,109 +0,0 @@
|
|
1
|
-
PATH
|
2
|
-
remote: .
|
3
|
-
specs:
|
4
|
-
positioning (0.1.2)
|
5
|
-
activerecord (>= 6.1)
|
6
|
-
activesupport (>= 6.1)
|
7
|
-
|
8
|
-
GEM
|
9
|
-
remote: https://rubygems.org/
|
10
|
-
specs:
|
11
|
-
activemodel (7.1.3.2)
|
12
|
-
activesupport (= 7.1.3.2)
|
13
|
-
activerecord (7.1.3.2)
|
14
|
-
activemodel (= 7.1.3.2)
|
15
|
-
activesupport (= 7.1.3.2)
|
16
|
-
timeout (>= 0.4.0)
|
17
|
-
activesupport (7.1.3.2)
|
18
|
-
base64
|
19
|
-
bigdecimal
|
20
|
-
concurrent-ruby (~> 1.0, >= 1.0.2)
|
21
|
-
connection_pool (>= 2.2.5)
|
22
|
-
drb
|
23
|
-
i18n (>= 1.6, < 2)
|
24
|
-
minitest (>= 5.1)
|
25
|
-
mutex_m
|
26
|
-
tzinfo (~> 2.0)
|
27
|
-
ast (2.4.2)
|
28
|
-
base64 (0.2.0)
|
29
|
-
bigdecimal (3.1.6)
|
30
|
-
concurrent-ruby (1.2.3)
|
31
|
-
connection_pool (2.4.1)
|
32
|
-
drb (2.2.0)
|
33
|
-
ruby2_keywords
|
34
|
-
i18n (1.14.1)
|
35
|
-
concurrent-ruby (~> 1.0)
|
36
|
-
json (2.7.1)
|
37
|
-
language_server-protocol (3.17.0.3)
|
38
|
-
lint_roller (1.1.0)
|
39
|
-
minitest (5.22.1)
|
40
|
-
minitest-hooks (1.5.1)
|
41
|
-
minitest (> 5.3)
|
42
|
-
mocha (2.1.0)
|
43
|
-
ruby2_keywords (>= 0.0.5)
|
44
|
-
mutex_m (0.2.0)
|
45
|
-
mysql2 (0.5.6)
|
46
|
-
parallel (1.24.0)
|
47
|
-
parser (3.3.0.5)
|
48
|
-
ast (~> 2.4.1)
|
49
|
-
racc
|
50
|
-
pg (1.5.5)
|
51
|
-
racc (1.7.3)
|
52
|
-
rainbow (3.1.1)
|
53
|
-
rake (13.1.0)
|
54
|
-
regexp_parser (2.9.0)
|
55
|
-
rexml (3.2.6)
|
56
|
-
rubocop (1.59.0)
|
57
|
-
json (~> 2.3)
|
58
|
-
language_server-protocol (>= 3.17.0)
|
59
|
-
parallel (~> 1.10)
|
60
|
-
parser (>= 3.2.2.4)
|
61
|
-
rainbow (>= 2.2.2, < 4.0)
|
62
|
-
regexp_parser (>= 1.8, < 3.0)
|
63
|
-
rexml (>= 3.2.5, < 4.0)
|
64
|
-
rubocop-ast (>= 1.30.0, < 2.0)
|
65
|
-
ruby-progressbar (~> 1.7)
|
66
|
-
unicode-display_width (>= 2.4.0, < 3.0)
|
67
|
-
rubocop-ast (1.30.0)
|
68
|
-
parser (>= 3.2.1.0)
|
69
|
-
rubocop-performance (1.20.2)
|
70
|
-
rubocop (>= 1.48.1, < 2.0)
|
71
|
-
rubocop-ast (>= 1.30.0, < 2.0)
|
72
|
-
ruby-progressbar (1.13.0)
|
73
|
-
ruby2_keywords (0.0.5)
|
74
|
-
sqlite3 (1.7.2-arm64-darwin)
|
75
|
-
sqlite3 (1.7.2-x86_64-linux)
|
76
|
-
standard (1.33.0)
|
77
|
-
language_server-protocol (~> 3.17.0.2)
|
78
|
-
lint_roller (~> 1.0)
|
79
|
-
rubocop (~> 1.59.0)
|
80
|
-
standard-custom (~> 1.0.0)
|
81
|
-
standard-performance (~> 1.3)
|
82
|
-
standard-custom (1.0.2)
|
83
|
-
lint_roller (~> 1.0)
|
84
|
-
rubocop (~> 1.50)
|
85
|
-
standard-performance (1.3.1)
|
86
|
-
lint_roller (~> 1.1)
|
87
|
-
rubocop-performance (~> 1.20.2)
|
88
|
-
timeout (0.4.1)
|
89
|
-
tzinfo (2.0.6)
|
90
|
-
concurrent-ruby (~> 1.0)
|
91
|
-
unicode-display_width (2.5.0)
|
92
|
-
|
93
|
-
PLATFORMS
|
94
|
-
arm64-darwin-21
|
95
|
-
x86_64-linux
|
96
|
-
|
97
|
-
DEPENDENCIES
|
98
|
-
minitest (~> 5.0)
|
99
|
-
minitest-hooks (~> 1.5.1)
|
100
|
-
mocha (~> 2.1.0)
|
101
|
-
mysql2 (~> 0.5.6)
|
102
|
-
pg (~> 1.5.5)
|
103
|
-
positioning!
|
104
|
-
rake (~> 13.0)
|
105
|
-
sqlite3 (~> 1.7.2)
|
106
|
-
standard (~> 1.3)
|
107
|
-
|
108
|
-
BUNDLED WITH
|
109
|
-
2.3.8
|