positioning 0.1.4 → 0.1.6

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: 2863317333ca4e36b7c8aecb178fb38f4489fc4dd76eb771c053769eb82cfbe2
4
- data.tar.gz: 13ad7808c1beb5ffaff7d97849b48e194915eeb043e541254843bb22ecfc167d
3
+ metadata.gz: 2fa6907a0507b7978c58578596c4e6ca16b7e334eb98b3fa42cba47a0d0b89b5
4
+ data.tar.gz: ed8f3126f69cb0f8780244a05d48e46abd0b64468ad47838f0d5827b4fa943ff
5
5
  SHA512:
6
- metadata.gz: dfcf0d2652e7c9e7ac65e5a1c885edae966ec0d7bc7119b3691c13b2c34c8ad434c6a7e8590e0ff76e550000cddd8cc3b2b2daf72b0626803d988ed21d6e8d7c
7
- data.tar.gz: bcdd1517650a8327eaa63ebed37bdcf2cc236beaad383eed23c3e063dfca1031c00714acf99542e8dca0d7320a53fcba6181da24f1e60fe0e4c706e870dd23ae
6
+ metadata.gz: 5d35b26bf717252dc30d828b2fff2b5b36c82ccd5b33d5480798cc57e38bacf9434120d2a478d448998c368286272a9dc2604cb8d3ebd071da0a55c8fa4ad5ba
7
+ data.tar.gz: 3b9c21bb1a3fe42c0799ffe6e991b29f7c17fd4efec8ff3b159afa41cd8a6b8b1e975e47c8e69e22dfd673352b105f2c55d85887a07d90e528b2cd0c54b3a318
data/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.1.6] - 2024-03-05
4
+
5
+ - Allow the position to be passed as a JSON object so that we can pass in complex positions from the browser more easily.
6
+
7
+ ## [0.1.5] - 2024-03-04
8
+
9
+ - Allow empty strings to represent nil for the purposes of solidifying a position
10
+
3
11
  ## [0.1.4] - 2024-03-04
4
12
 
5
13
  - Fix bug relating to relative position hash coming from Rails being a Hash With Indifferent Access
@@ -96,16 +96,27 @@ module Positioning
96
96
  end
97
97
 
98
98
  def solidify_position
99
- position_before_type_cast = @positioned.read_attribute_before_type_cast @column
100
- position_before_type_cast.to_sym if position_before_type_cast.is_a? String
101
- position_before_type_cast = position_before_type_cast.symbolize_keys if position_before_type_cast.is_a? Hash
99
+ position_before_type_cast = @positioned.read_attribute_before_type_cast(@column)
100
+
101
+ if position_before_type_cast.is_a? String
102
+ begin
103
+ position_before_type_cast = JSON.parse(position_before_type_cast, symbolize_names: true)
104
+ rescue JSON::ParserError
105
+ end
106
+
107
+ if position_before_type_cast.is_a?(String) && position_before_type_cast.present?
108
+ position_before_type_cast = position_before_type_cast.to_sym
109
+ end
110
+ elsif position_before_type_cast.is_a? Hash
111
+ position_before_type_cast = position_before_type_cast.symbolize_keys
112
+ end
102
113
 
103
114
  case position_before_type_cast
104
115
  when Integer
105
116
  self.position = position_before_type_cast.clamp(1..last_position)
106
- when :first, {after: nil}
117
+ when :first, {after: nil}, {after: ""}
107
118
  self.position = 1
108
- when nil, :last, {before: nil}
119
+ when nil, "", :last, {before: nil}, {before: ""}
109
120
  self.position = last_position
110
121
  when Hash
111
122
  relative_position, relative_record_or_primary_key = *position_before_type_cast.first
@@ -135,8 +146,9 @@ module Positioning
135
146
 
136
147
  unless position.is_a? Integer
137
148
  raise Error.new,
138
- "`#{@column}` must be an Integer, :first, :last, before: #{base_class.name}, " \
139
- "after: #{base_class.name}, or nil"
149
+ %(`#{@column}` must be an Integer, :first, :last, ) +
150
+ %{before: (#{base_class.name}, #{primary_key_column}, nil, or ""), } +
151
+ %{after: (#{base_class.name}, #{primary_key_column}, nil or ""), nil or ""}
140
152
  end
141
153
  end
142
154
 
@@ -1,3 +1,3 @@
1
1
  module Positioning
2
- VERSION = "0.1.4"
2
+ VERSION = "0.1.6"
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.1.4
4
+ version: 0.1.6
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-03-04 00:00:00.000000000 Z
11
+ date: 2024-03-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport