jpie 2.1.3 → 2.1.4

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: ff291316aa0dff52e52421edfb945d6c450224761af9552da4cf80c5d5939385
4
- data.tar.gz: d20184a0ff94d93da07a167088fdd5ea12346698e5324554a9ee5b4e232784f6
3
+ metadata.gz: 23a1e7f0dd69ee73d5a8f684ac39005fca7081222517086e5f708ffd8ca7815b
4
+ data.tar.gz: c2ae85e3db1522db8891a6ec0cba3956af94993e1658bdbe0e2a517af9954740
5
5
  SHA512:
6
- metadata.gz: 5ef0a9f42b050d26a21545044b985d5deb9cd3417e073e5ec26d9fc462f954c687c547fd850f1a93b3bd7567d0d1b24418f289b61373792a5f6b7005af90885c
7
- data.tar.gz: fa80175057fb038cc79ec2c3ee5fa01ac33758c72fd4f618369cd245f8dd3a4c2a2c8c7612ed2ff49f49374514aafb27abab55c801866821a92ae502582c2970
6
+ metadata.gz: 2fa70259c383d4f694f0071384f3b9a8f6f46e3b26765644bbaa45045c4be86454ba9a934b1ec79f9571f1846ae54cdd3b61ec439ba9c000155ee74feaeef1f8
7
+ data.tar.gz: 3b00c7a05a52bc30b81109a09e95c65cdd6602facba9e8c92b0011ca3a6b3cc0eecb4da2b15704a5d2df03325b70f3aed474988034cefdd7111089815eab8e39
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- jpie (2.1.3)
4
+ jpie (2.1.4)
5
5
  actionpack (~> 8.1, >= 8.1.0)
6
6
  pg_query (>= 4)
7
7
  prosopite (>= 1)
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "json_api/support/sort_value_comparison"
4
+
3
5
  module JSONAPI
4
6
  module Relationships
5
7
  module Sorting
@@ -75,11 +77,7 @@ module JSONAPI
75
77
  end
76
78
 
77
79
  def compare_values(value_a, value_b)
78
- return 0 if value_a.nil? && value_b.nil?
79
- return -1 if value_a.nil?
80
- return 1 if value_b.nil?
81
-
82
- value_a <=> value_b
80
+ JSONAPI::Support::SortValueComparison.compare(value_a, value_b)
83
81
  end
84
82
 
85
83
  def validate_sort_param
@@ -19,6 +19,7 @@ module JSONAPI
19
19
  def scope_with_includes(scope)
20
20
  includes = parse_include_param
21
21
  return scope unless includes.any?
22
+ return scope if scope.is_a?(Array)
22
23
 
23
24
  inc_hash = includes_to_hash(includes)
24
25
  hash_contains_polymorphic?(inc_hash, model_class) ? scope.preload(inc_hash) : scope.includes(inc_hash)
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "json_api/support/sort_value_comparison"
4
+
3
5
  module JSONAPI
4
6
  module Support
5
7
  module Sorting
@@ -77,11 +79,7 @@ module JSONAPI
77
79
  end
78
80
 
79
81
  def compare_values(value_a, value_b)
80
- return 0 if value_a.nil? && value_b.nil?
81
- return -1 if value_a.nil?
82
- return 1 if value_b.nil?
83
-
84
- value_a <=> value_b
82
+ SortValueComparison.compare(value_a, value_b)
85
83
  end
86
84
  end
87
85
  end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ module JSONAPI
4
+ module Support
5
+ # Compares two values for stable sort ordering. Ruby 3.4+ TrueClass#<=> returns nil
6
+ # when operands differ (true <=> false), so booleans are normalized before <=>.
7
+ module SortValueComparison
8
+ module_function
9
+
10
+ def compare(value_a, value_b)
11
+ return 0 if value_a.nil? && value_b.nil?
12
+ return -1 if value_a.nil?
13
+ return 1 if value_b.nil?
14
+
15
+ value_a = value_a ? 1 : 0 if value_a in TrueClass | FalseClass
16
+ value_b = value_b ? 1 : 0 if value_b in TrueClass | FalseClass
17
+
18
+ result = value_a <=> value_b
19
+ return result unless result.nil?
20
+
21
+ detail = "#{value_a.class.name} (#{value_a.inspect}), #{value_b.class.name} (#{value_b.inspect})"
22
+ raise ArgumentError, "incomparable sort values: #{detail}"
23
+ end
24
+ end
25
+ end
26
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module JSONAPI
4
- VERSION = "2.1.3"
4
+ VERSION = "2.1.4"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jpie
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.3
4
+ version: 2.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Emil Kampp
@@ -192,6 +192,7 @@ files:
192
192
  - lib/json_api/support/resource_identifier.rb
193
193
  - lib/json_api/support/responders.rb
194
194
  - lib/json_api/support/sort_parsing.rb
195
+ - lib/json_api/support/sort_value_comparison.rb
195
196
  - lib/json_api/support/type_conversion.rb
196
197
  - lib/json_api/testing.rb
197
198
  - lib/json_api/testing/rspec.rb