positioning 0.4.6 → 0.4.8
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 +4 -0
- data/Gemfile +8 -13
- data/README.md +11 -0
- data/lib/positioning/mechanisms.rb +2 -4
- data/lib/positioning/version.rb +1 -1
- data/lib/positioning.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 4b3882c55b3e657ad75fb0cabf586ae890506ba89acc34a198d32c31c2aa8521
|
|
4
|
+
data.tar.gz: e8a3ffa61736d782745416743cf926daf2170be8beee94189adf9bf962515fd5
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 77acd60a82aef76786848043aeebe7ed58e1f6725592ef21ff0265eed16d1fdc4fd52024988b4e86e7537c990e6f6f1be8c6bb7392250a30dee8901ead8b3179
|
|
7
|
+
data.tar.gz: ff80e90b8ed3d4d96f24f26c879a0fb4d570d92b22c4159ecc79683e9f56b39df46c0cb524a7a478781905a3e46bdc44012f6cca7d959f9b0d226f69de67d33d
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
## [Unreleased]
|
|
2
2
|
|
|
3
|
+
## [0.4.7] - 2025-08-09
|
|
4
|
+
|
|
5
|
+
- Fix `solidify_position` so that it properly raises an error for an invalid string position.
|
|
6
|
+
|
|
3
7
|
## [0.4.6] - 2025-05-01
|
|
4
8
|
|
|
5
9
|
- Fix healing for positioning with nullable scope (parent in trees, for example). Thanks @pyromaniac!
|
data/Gemfile
CHANGED
|
@@ -3,13 +3,13 @@ source "https://rubygems.org"
|
|
|
3
3
|
# Specify your gem's dependencies in positioning.gemspec
|
|
4
4
|
gemspec
|
|
5
5
|
|
|
6
|
-
gem "rake", "~> 13.
|
|
6
|
+
gem "rake", "~> 13.3"
|
|
7
7
|
|
|
8
|
-
gem "minitest", "~>
|
|
9
|
-
gem "minitest-hooks", "~> 1.5.
|
|
10
|
-
gem "mocha", "~>
|
|
8
|
+
gem "minitest", "~> 6.0"
|
|
9
|
+
gem "minitest-hooks", "~> 1.5.3"
|
|
10
|
+
gem "mocha", "~> 3.0.1"
|
|
11
11
|
|
|
12
|
-
gem "standard", "~> 1.
|
|
12
|
+
gem "standard", "~> 1.52.0"
|
|
13
13
|
|
|
14
14
|
if ENV["RAILS_VERSION"]
|
|
15
15
|
gem "activerecord", ENV["RAILS_VERSION"]
|
|
@@ -18,14 +18,9 @@ end
|
|
|
18
18
|
|
|
19
19
|
case ENV["DB"]
|
|
20
20
|
when "sqlite"
|
|
21
|
-
|
|
22
|
-
Gem::Version.new(ENV["RAILS_VERSION"]) >= Gem::Version.new("7.2")
|
|
23
|
-
gem "sqlite3", "~> 2.2.0"
|
|
24
|
-
else
|
|
25
|
-
gem "sqlite3", "~> 1.7.2"
|
|
26
|
-
end
|
|
21
|
+
gem "sqlite3", "~> 2.9.0"
|
|
27
22
|
when "postgresql"
|
|
28
|
-
gem "pg", "~> 1.
|
|
23
|
+
gem "pg", "~> 1.6.3"
|
|
29
24
|
else
|
|
30
|
-
gem "mysql2", "
|
|
25
|
+
gem "mysql2", "0.5.6"
|
|
31
26
|
end
|
data/README.md
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# Positioning
|
|
2
2
|
|
|
3
|
+
[](https://github.com/brendon/positioning/actions/workflows/main.yml)
|
|
4
|
+
|
|
3
5
|
The aim of this gem is to allow you to easily position Active Record model instances within a scope of your choosing. In an ideal world this gem will give your model instances sequential integer positions beginning with `1`. Attempts are made to make all changes within a transaction so that position integers remain consistent. To this end, directly assigning a position is discouraged, instead you can move items by declaring an item's prior or subsequent item in the list and your item will be moved to be relative to that item.
|
|
4
6
|
|
|
5
7
|
Positioning supports multiple lists per model with global, simple, and complex scopes.
|
|
@@ -267,6 +269,15 @@ item.update list: other_list, position: {after: 11}
|
|
|
267
269
|
|
|
268
270
|
It's important to note that in the examples above, `other_item` must already belong to the `other_list` scope.
|
|
269
271
|
|
|
272
|
+
##### Single Table Inheritance and Abstract Models
|
|
273
|
+
Positioning requires a concrete table to work with and considers all records within that table as being in some scope. Therefore, it currently isn't possible to use `positioned` on abstract subclasses or when using STI. All calls to `position` must be on the base class.
|
|
274
|
+
|
|
275
|
+
If you must position child models separately, scope their position by the `type` column.
|
|
276
|
+
|
|
277
|
+
```rb
|
|
278
|
+
positioned on: [:type]
|
|
279
|
+
```
|
|
280
|
+
|
|
270
281
|
## Concurrency
|
|
271
282
|
|
|
272
283
|
The queries that this gem runs (especially those that seek the next position integer available) are vulnerable to race conditions. To this end, we lock the scope records to ensure that our model callbacks that determine and assign positions run sequentially. Previously we used an Advisory Lock for this purpose but this was difficult to test and a bit overkill in most situations. Where a scope doesn't exist, we lock all the records in the table.
|
|
@@ -162,9 +162,7 @@ module Positioning
|
|
|
162
162
|
solidified_position -= 1 if in_positioning_scope? && position_was < solidified_position
|
|
163
163
|
|
|
164
164
|
self.position = solidified_position
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
unless position.is_a? Integer
|
|
165
|
+
else
|
|
168
166
|
raise Error.new,
|
|
169
167
|
%(`#{@column}` must be an Integer, :first, :last, ) +
|
|
170
168
|
%{before: (#{base_class.name}, #{primary_key}, nil, or ""), } +
|
|
@@ -224,7 +222,7 @@ module Positioning
|
|
|
224
222
|
|
|
225
223
|
def destroyed_via_positioning_scope?
|
|
226
224
|
@positioned.destroyed_by_association && scope_columns.any? do |scope_column|
|
|
227
|
-
@positioned.destroyed_by_association.foreign_key
|
|
225
|
+
Array(@positioned.destroyed_by_association.foreign_key).include?(scope_column)
|
|
228
226
|
end
|
|
229
227
|
end
|
|
230
228
|
end
|
data/lib/positioning/version.rb
CHANGED
data/lib/positioning.rb
CHANGED
|
@@ -35,7 +35,7 @@ module Positioning
|
|
|
35
35
|
reflection = reflections[scope_component]
|
|
36
36
|
|
|
37
37
|
if reflection&.belongs_to?
|
|
38
|
-
positioning_columns[column][:scope_columns]
|
|
38
|
+
positioning_columns[column][:scope_columns].concat Array(reflection.foreign_key)
|
|
39
39
|
positioning_columns[column][:scope_columns] << reflection.foreign_type if reflection.polymorphic?
|
|
40
40
|
positioning_columns[column][:scope_associations] << reflection.name
|
|
41
41
|
else
|
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.4.
|
|
4
|
+
version: 0.4.8
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Brendon Muir
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2026-03-28 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: activesupport
|