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 +4 -4
- data/Gemfile.lock +1 -1
- data/lib/json_api/controllers/concerns/relationships/sorting.rb +3 -5
- data/lib/json_api/controllers/concerns/resource_actions/include_preloading.rb +1 -0
- data/lib/json_api/support/concerns/sorting.rb +3 -5
- data/lib/json_api/support/sort_value_comparison.rb +26 -0
- data/lib/json_api/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 23a1e7f0dd69ee73d5a8f684ac39005fca7081222517086e5f708ffd8ca7815b
|
|
4
|
+
data.tar.gz: c2ae85e3db1522db8891a6ec0cba3956af94993e1658bdbe0e2a517af9954740
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 2fa70259c383d4f694f0071384f3b9a8f6f46e3b26765644bbaa45045c4be86454ba9a934b1ec79f9571f1846ae54cdd3b61ec439ba9c000155ee74feaeef1f8
|
|
7
|
+
data.tar.gz: 3b00c7a05a52bc30b81109a09e95c65cdd6602facba9e8c92b0011ca3a6b3cc0eecb4da2b15704a5d2df03325b70f3aed474988034cefdd7111089815eab8e39
|
data/Gemfile.lock
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
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
|
data/lib/json_api/version.rb
CHANGED
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.
|
|
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
|