jpie 2.1.3 → 2.1.5
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/bin/release +32 -0
- data/lib/json_api/controllers/concerns/controller_helpers/parsing.rb +2 -4
- data/lib/json_api/controllers/concerns/relationships/sorting.rb +4 -6
- data/lib/json_api/controllers/concerns/resource_actions/field_validation.rb +1 -1
- 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 +3 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: e03bce6fffc1ed66774e89f660afda17460b6d837b07f549b8c17698d252dccd
|
|
4
|
+
data.tar.gz: 7a8ea2397e9ebfab913bfd7a4e13cab637b4e7fcc7829e7e16e37da019c5fd3e
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 27dc32299a441b790c9ae4f3890ad5f12f492d5a2027f1f4a0929923a79cbbaf1b1d78746e29d033c2ee85e4d9bf5c1dae24051d2f447eff5bea50a2a36c28b9
|
|
7
|
+
data.tar.gz: 7fc2d6613e25d73ec7abaafc7dfe5066c9a7a4b79ea0ffc326964f114a3203909382ee68a62ee507617302309ad7517eb01f92ef4e28f2facd208e9cda769dad
|
data/Gemfile.lock
CHANGED
data/bin/release
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
VERSION_FILE = File.expand_path("../../lib/json_api/version.rb", __FILE__)
|
|
5
|
+
|
|
6
|
+
bump_type = ARGV[0]
|
|
7
|
+
|
|
8
|
+
unless %w[major minor patch].include?(bump_type)
|
|
9
|
+
abort "Usage: bin/release [major|minor|patch]"
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
content = File.read(VERSION_FILE)
|
|
13
|
+
current = content.match(/VERSION\s*=\s*["'](.+?)["']/)[1]
|
|
14
|
+
parts = current.split(".").map(&:to_i)
|
|
15
|
+
|
|
16
|
+
new_version = case bump_type
|
|
17
|
+
when "major" then [parts[0] + 1, 0, 0]
|
|
18
|
+
when "minor" then [parts[0], parts[1] + 1, 0]
|
|
19
|
+
when "patch" then [parts[0], parts[1], parts[2] + 1]
|
|
20
|
+
end.join(".")
|
|
21
|
+
|
|
22
|
+
File.write(VERSION_FILE, content.gsub(/VERSION\s*=\s*["'].+?["']/, %(VERSION = "#{new_version}")))
|
|
23
|
+
|
|
24
|
+
puts "Bumped #{current} → #{new_version}"
|
|
25
|
+
|
|
26
|
+
system("git add #{VERSION_FILE}")
|
|
27
|
+
system(%(git commit -m "Bump version to #{new_version}"))
|
|
28
|
+
|
|
29
|
+
print "OTP code: "
|
|
30
|
+
ENV["GEM_HOST_OTP_CODE"] = $stdin.gets.strip
|
|
31
|
+
|
|
32
|
+
exec("rake release")
|
|
@@ -117,10 +117,8 @@ module JSONAPI
|
|
|
117
117
|
end
|
|
118
118
|
end
|
|
119
119
|
|
|
120
|
-
def valid_sort_fields_for_resource(resource_class
|
|
121
|
-
|
|
122
|
-
resource_sortable_fields = resource_class.permitted_sortable_fields.map(&:to_sym)
|
|
123
|
-
(model_columns + resource_sortable_fields).uniq.map(&:to_s)
|
|
120
|
+
def valid_sort_fields_for_resource(resource_class)
|
|
121
|
+
resource_class.permitted_sortable_fields.map(&:to_s)
|
|
124
122
|
end
|
|
125
123
|
end
|
|
126
124
|
end
|
|
@@ -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
|
|
@@ -94,7 +92,7 @@ module JSONAPI
|
|
|
94
92
|
|
|
95
93
|
def validate_sort_fields_for_association(sorts, association)
|
|
96
94
|
resource_class = ResourceLoader.find_for_model(association.klass)
|
|
97
|
-
valid_fields = valid_sort_fields_for_resource(resource_class
|
|
95
|
+
valid_fields = valid_sort_fields_for_resource(resource_class)
|
|
98
96
|
invalid_fields = invalid_sort_fields_for_columns(sorts, valid_fields)
|
|
99
97
|
return if invalid_fields.empty?
|
|
100
98
|
|
|
@@ -17,7 +17,7 @@ module JSONAPI
|
|
|
17
17
|
sorts = parse_sort_param
|
|
18
18
|
return if sorts.empty?
|
|
19
19
|
|
|
20
|
-
valid = valid_sort_fields_for_resource(@resource_class
|
|
20
|
+
valid = valid_sort_fields_for_resource(@resource_class)
|
|
21
21
|
invalid = invalid_sort_fields_for_columns(sorts, valid)
|
|
22
22
|
render_sort_errors(invalid) if invalid.any?
|
|
23
23
|
end
|
|
@@ -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.5
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Emil Kampp
|
|
@@ -103,6 +103,7 @@ files:
|
|
|
103
103
|
- README.md
|
|
104
104
|
- Rakefile
|
|
105
105
|
- bin/console
|
|
106
|
+
- bin/release
|
|
106
107
|
- bin/setup
|
|
107
108
|
- jpie.gemspec
|
|
108
109
|
- lib/jpie.rb
|
|
@@ -192,6 +193,7 @@ files:
|
|
|
192
193
|
- lib/json_api/support/resource_identifier.rb
|
|
193
194
|
- lib/json_api/support/responders.rb
|
|
194
195
|
- lib/json_api/support/sort_parsing.rb
|
|
196
|
+
- lib/json_api/support/sort_value_comparison.rb
|
|
195
197
|
- lib/json_api/support/type_conversion.rb
|
|
196
198
|
- lib/json_api/testing.rb
|
|
197
199
|
- lib/json_api/testing/rspec.rb
|