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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 88f71996b9993bcc361ea0306aac58481278d85d907a30fb00da09ac69521ea3
4
- data.tar.gz: b9e378a4e4a93a20b645138f732dc0031f5cce9210f4ded0122325bc9fde8739
3
+ metadata.gz: 4b3882c55b3e657ad75fb0cabf586ae890506ba89acc34a198d32c31c2aa8521
4
+ data.tar.gz: e8a3ffa61736d782745416743cf926daf2170be8beee94189adf9bf962515fd5
5
5
  SHA512:
6
- metadata.gz: 7bd750e9f02221a4643ecbc590ca46ed133d1ecb2bbfb69162c319997b1e5eb70ceea971f3dd14c7f0e45bb214d56d516a4e2ff160bb8aab916804beba629bfc
7
- data.tar.gz: f3e8773fc1984c65662c374066529bbf3bc597e32f4f45f018383ad30d307354ab4c8d85bffee2ca7a5cdabb6d4fac72dda12491228d6cdd6117ec251292fe58
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.0"
6
+ gem "rake", "~> 13.3"
7
7
 
8
- gem "minitest", "~> 5.0"
9
- gem "minitest-hooks", "~> 1.5.1"
10
- gem "mocha", "~> 2.1.0"
8
+ gem "minitest", "~> 6.0"
9
+ gem "minitest-hooks", "~> 1.5.3"
10
+ gem "mocha", "~> 3.0.1"
11
11
 
12
- gem "standard", "~> 1.3"
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
- if ENV["RAILS_VERSION"] &&
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.5.5"
23
+ gem "pg", "~> 1.6.3"
29
24
  else
30
- gem "mysql2", "~> 0.5.6"
25
+ gem "mysql2", "0.5.6"
31
26
  end
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # Positioning
2
2
 
3
+ [![Ruby](https://github.com/brendon/positioning/actions/workflows/main.yml/badge.svg)](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
- end
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 == scope_column
225
+ Array(@positioned.destroyed_by_association.foreign_key).include?(scope_column)
228
226
  end
229
227
  end
230
228
  end
@@ -1,3 +1,3 @@
1
1
  module Positioning
2
- VERSION = "0.4.6"
2
+ VERSION = "0.4.8"
3
3
  end
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] << reflection.foreign_key
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.6
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: 2025-05-01 00:00:00.000000000 Z
11
+ date: 2026-03-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport