positioning 0.1.1 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e0d883985a674ffd2262b5ae6fbfa004cdeb21f76cb4f47b293c252498abf047
4
- data.tar.gz: 6b2e92166a991cc255e9db3eacd1f3a504e165033d5351285c6200e6a4e44f78
3
+ metadata.gz: 20e2658aa131e9c641fc3b5bdd2f685d64af56d56a53abb0eef4a25f12b4f293
4
+ data.tar.gz: 61d5b5e9afb5ad0d037ccb2a14185dfe0fca705cb0850f89e436d1e371608d9f
5
5
  SHA512:
6
- metadata.gz: 3a21c3d4429ba5bb280490e555781023a4062df76760d37ae77c073cacb8e875c3a57e9735f15e042d9ed63445865ce1bddf4e52ef3a6db79896945fd8b417e2
7
- data.tar.gz: 658091668c0a500dddd65275bfabc4506358fce770cc6b9a01026f7803d26a10386e37fec883a13a96e3f42be8d879d936efafec5127880b9e55fa5ca62ee0d2
6
+ metadata.gz: 51c9fa527fea19618a9b5362cc81cce367dfa15039328a3085598fd1c5ea8e2f6b8bcf92b650c82d83fb0e221ef307b893580a4172fb0f3c94200a8cdb1579c4
7
+ data.tar.gz: 8ca5d909229d1c2d8f1712c5ca21275ac75f733de7bf799c7c3d8777f609116efa6127b7a657d09e6a5396769c5451a8a44218941e15d836abaa3b99e954bef3
data/CHANGELOG.md CHANGED
@@ -1,9 +1,19 @@
1
1
  ## [Unreleased]
2
2
 
3
- ## [0.1.1] - 2024-02-07
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
+
9
+ ## [0.1.2] - 2024-02-29
10
+
11
+ - Fix a bug related to the scope changing with an explicitly set position value that is the same as the original position.
12
+
13
+ ## [0.1.1] - 2024-02-25
4
14
 
5
15
  - Fix issues with STI based models
6
16
 
7
- ## [0.1.0] - 2024-02-07
17
+ ## [0.1.0] - 2024-02-24
8
18
 
9
19
  - Initial release
data/Gemfile CHANGED
@@ -8,3 +8,8 @@ gem "rake", "~> 13.0"
8
8
  gem "minitest", "~> 5.0"
9
9
 
10
10
  gem "standard", "~> 1.3"
11
+
12
+ if ENV["RAILS_VERSION"]
13
+ gem "activerecord", ENV["RAILS_VERSION"]
14
+ gem "activesupport", ENV["RAILS_VERSION"]
15
+ end
@@ -20,29 +20,16 @@ module Positioning
20
20
  end
21
21
 
22
22
  def update_position
23
- # If we're changing scope but not explicitly setting the position then we set the position
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
- record_scope = base_class.where("#{primary_key_column}": primary_key)
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
-
43
- # If the position integer was set to the same as its prior value but the scope has changed then
44
- # we need to tell Rails that it has changed so that it gets updated from the temporary 0 value.
45
- position_will_change!
46
33
  elsif position_was > position
47
34
  expand(positioning_scope, position..position_was)
48
35
  else
@@ -69,6 +56,10 @@ module Positioning
69
56
  @positioned.send primary_key_column
70
57
  end
71
58
 
59
+ def record_scope
60
+ base_class.where("#{primary_key_column}": primary_key)
61
+ end
62
+
72
63
  def position
73
64
  @positioned.send @column
74
65
  end
@@ -77,12 +68,21 @@ module Positioning
77
68
  @positioned.send :"#{@column}=", position
78
69
  end
79
70
 
71
+ def clear_position
72
+ self.position = nil
73
+ end
74
+
80
75
  def position_changed?
81
76
  @positioned.send :"#{@column}_changed?"
82
77
  end
83
78
 
84
- def position_will_change!
85
- @positioned.send :"#{@column}_will_change!"
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
86
  end
87
87
 
88
88
  def expand(scope, range)
@@ -126,8 +126,6 @@ module Positioning
126
126
  raise Error.new, "relative `#{@column}` record must be in the same scope"
127
127
  end
128
128
 
129
- position_was = base_class.where("#{primary_key_column}": primary_key).pick(@column)
130
-
131
129
  solidified_position = relative_record_scope.pick(@column)
132
130
  solidified_position += 1 if relative_position == :after
133
131
  solidified_position -= 1 if in_positioning_scope? && position_was < solidified_position
@@ -151,11 +149,15 @@ module Positioning
151
149
  end
152
150
 
153
151
  def positioning_scope
154
- base_class.where(@positioned.slice(*positioning_columns)).order(@column)
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)
155
157
  end
156
158
 
157
159
  def in_positioning_scope?
158
- @positioned.persisted? && positioning_scope.exists?(primary_key)
160
+ @positioned.persisted? && positioning_scope.where("#{primary_key_column}": primary_key).exists?
159
161
  end
160
162
 
161
163
  def positioning_scope_changed?
@@ -1,3 +1,3 @@
1
1
  module Positioning
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.3"
3
3
  end
data/lib/positioning.rb CHANGED
@@ -34,6 +34,11 @@ module Positioning
34
34
  define_method(:"prior_#{column}") { Mechanisms.new(self, column).prior }
35
35
  define_method(:"subsequent_#{column}") { Mechanisms.new(self, column).subsequent }
36
36
 
37
+ redefine_method(:"#{column}=") do |position|
38
+ send :"#{column}_will_change!"
39
+ super(position)
40
+ end
41
+
37
42
  before_create { Mechanisms.new(self, column).create_position }
38
43
  before_update { Mechanisms.new(self, column).update_position }
39
44
  after_destroy { Mechanisms.new(self, column).destroy_position }
data/positioning.gemspec CHANGED
@@ -13,7 +13,7 @@ Gem::Specification.new do |spec|
13
13
 
14
14
  spec.metadata["homepage_uri"] = spec.homepage
15
15
  spec.metadata["source_code_uri"] = "https://github.com/brendon/positioning"
16
- spec.metadata["changelog_uri"] = "https://github.com/brendon/positioning/CHANGELOG.md"
16
+ spec.metadata["changelog_uri"] = "https://github.com/brendon/positioning/blob/main/CHANGELOG.md"
17
17
 
18
18
  # Specify which files should be added to the gem when it is released.
19
19
  # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
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.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-02-25 00:00:00.000000000 Z
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
@@ -133,7 +132,7 @@ licenses:
133
132
  metadata:
134
133
  homepage_uri: https://github.com/brendon/positioning
135
134
  source_code_uri: https://github.com/brendon/positioning
136
- changelog_uri: https://github.com/brendon/positioning/CHANGELOG.md
135
+ changelog_uri: https://github.com/brendon/positioning/blob/main/CHANGELOG.md
137
136
  post_install_message:
138
137
  rdoc_options: []
139
138
  require_paths:
data/Gemfile.lock DELETED
@@ -1,109 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- positioning (0.1.1)
5
- activerecord (>= 6.1)
6
- activesupport (>= 6.1)
7
-
8
- GEM
9
- remote: https://rubygems.org/
10
- specs:
11
- activemodel (7.1.3)
12
- activesupport (= 7.1.3)
13
- activerecord (7.1.3)
14
- activemodel (= 7.1.3)
15
- activesupport (= 7.1.3)
16
- timeout (>= 0.4.0)
17
- activesupport (7.1.3)
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