positioning 0.2.4 → 0.2.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 02113cf1d0279ee7f3b304429eb5af8a4e6e46254f2397cae704191900cfd0a5
4
- data.tar.gz: b248f330a5b3373b396f487bb11008a14cdf1c6f292b6c63a7000dd1150cfa8a
3
+ metadata.gz: '04080c2e27b8d0545c86d69fb4a7794530971ca19c1e9db969181ff01bab2f96'
4
+ data.tar.gz: 3e81bbd7406e0221378d78e4404629c70eb84d82849d96c6a3506982cbfdf756
5
5
  SHA512:
6
- metadata.gz: 94333e70ecd013a4970c4667fb715e91fca7450bcb6c52dd57706d8134c8a02ab8fc698a4a2abcb34bbe69dac640f528cce45df351a2bb2d42958e2a77468f23
7
- data.tar.gz: f273602f9fff96622aa9d9d7706570629de601468b782e186df71936084053a2368595cf116827d4c1f86775cfa4ca150eef0e662895bf79c3afd6560d3002b0
6
+ metadata.gz: ef7cd59860371c435080925d38d994ac8b6a538de4c3a2687f602959792d7d9d1ba91c3df8c91c74ecf284f65ac432d7fc88b2d7ea3710c22c5f27641398f58e
7
+ data.tar.gz: 108ded7f5f7756f05dbc19b863bc723ed4e32e41737b6eecded5d0a6e0ab8a19e65a05bb330ce3625f5a61736ed0c4f816a3183efde8b7d17d0bcfbd5518ddda
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.2.5] - 2024-08-10
4
+
5
+ - Implemented composite primary key support. Thanks @jackozi for the original PR and the nudge to get this done!
6
+
3
7
  ## [0.2.4] - 2024-07-31
4
8
 
5
9
  - Avoid unnecessary SQL queries when the position hasn't changed.
@@ -50,12 +50,8 @@ module Positioning
50
50
  @positioned.class.base_class
51
51
  end
52
52
 
53
- def primary_key_column
54
- base_class.primary_key
55
- end
56
-
57
53
  def primary_key
58
- @positioned.send primary_key_column
54
+ base_class.primary_key
59
55
  end
60
56
 
61
57
  def quoted_column
@@ -63,7 +59,7 @@ module Positioning
63
59
  end
64
60
 
65
61
  def record_scope
66
- base_class.where("#{primary_key_column}": primary_key)
62
+ base_class.where(primary_key => [@positioned.id])
67
63
  end
68
64
 
69
65
  def position
@@ -125,19 +121,19 @@ module Positioning
125
121
  when nil, "", :last, {before: nil}, {before: ""}
126
122
  self.position = last_position
127
123
  when Hash
128
- relative_position, relative_record_or_primary_key = *position_before_type_cast.first
124
+ relative_position, relative_record_or_id = *position_before_type_cast.first
129
125
 
130
126
  unless [:before, :after].include? relative_position
131
127
  raise Error.new, "relative `#{@column}` must be either :before, :after"
132
128
  end
133
129
 
134
- relative_primary_key = if relative_record_or_primary_key.is_a? base_class
135
- relative_record_or_primary_key.send(primary_key_column)
130
+ relative_id = if relative_record_or_id.is_a? base_class
131
+ relative_record_or_id.id
136
132
  else
137
- relative_record_or_primary_key
133
+ relative_record_or_id
138
134
  end
139
135
 
140
- relative_record_scope = positioning_scope.where("#{primary_key_column}": relative_primary_key)
136
+ relative_record_scope = positioning_scope.where(primary_key => [relative_id])
141
137
 
142
138
  unless relative_record_scope.exists?
143
139
  raise Error.new, "relative `#{@column}` record must be in the same scope"
@@ -153,8 +149,8 @@ module Positioning
153
149
  unless position.is_a? Integer
154
150
  raise Error.new,
155
151
  %(`#{@column}` must be an Integer, :first, :last, ) +
156
- %{before: (#{base_class.name}, #{primary_key_column}, nil, or ""), } +
157
- %{after: (#{base_class.name}, #{primary_key_column}, nil or ""), nil or ""}
152
+ %{before: (#{base_class.name}, #{primary_key}, nil, or ""), } +
153
+ %{after: (#{base_class.name}, #{primary_key}, nil or ""), nil or ""}
158
154
  end
159
155
  end
160
156
 
@@ -175,7 +171,7 @@ module Positioning
175
171
  end
176
172
 
177
173
  def in_positioning_scope?
178
- @positioned.persisted? && positioning_scope.where("#{primary_key_column}": primary_key).exists?
174
+ @positioned.persisted? && positioning_scope.where(primary_key => [@positioned.id]).exists?
179
175
  end
180
176
 
181
177
  def positioning_scope_changed?
@@ -1,3 +1,3 @@
1
1
  module Positioning
2
- VERSION = "0.2.4"
2
+ VERSION = "0.2.5"
3
3
  end
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.2.4
4
+ version: 0.2.5
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-07-31 00:00:00.000000000 Z
11
+ date: 2024-08-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport