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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ff291316aa0dff52e52421edfb945d6c450224761af9552da4cf80c5d5939385
4
- data.tar.gz: d20184a0ff94d93da07a167088fdd5ea12346698e5324554a9ee5b4e232784f6
3
+ metadata.gz: e03bce6fffc1ed66774e89f660afda17460b6d837b07f549b8c17698d252dccd
4
+ data.tar.gz: 7a8ea2397e9ebfab913bfd7a4e13cab637b4e7fcc7829e7e16e37da019c5fd3e
5
5
  SHA512:
6
- metadata.gz: 5ef0a9f42b050d26a21545044b985d5deb9cd3417e073e5ec26d9fc462f954c687c547fd850f1a93b3bd7567d0d1b24418f289b61373792a5f6b7005af90885c
7
- data.tar.gz: fa80175057fb038cc79ec2c3ee5fa01ac33758c72fd4f618369cd245f8dd3a4c2a2c8c7612ed2ff49f49374514aafb27abab55c801866821a92ae502582c2970
6
+ metadata.gz: 27dc32299a441b790c9ae4f3890ad5f12f492d5a2027f1f4a0929923a79cbbaf1b1d78746e29d033c2ee85e4d9bf5c1dae24051d2f447eff5bea50a2a36c28b9
7
+ data.tar.gz: 7fc2d6613e25d73ec7abaafc7dfe5066c9a7a4b79ea0ffc326964f114a3203909382ee68a62ee507617302309ad7517eb01f92ef4e28f2facd208e9cda769dad
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)
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, model_class)
121
- model_columns = model_class.column_names.map(&:to_sym)
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
- 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
@@ -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, association.klass)
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, model_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
- 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.5"
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.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