From fe5e1f1d06fc03dcabfd3bccdf3f1fea728a4719 Mon Sep 17 00:00:00 2001 From: Dasun Pubudumal Date: Mon, 26 Jan 2026 11:26:55 +0000 Subject: [PATCH 01/16] Rails 8.1 fix --- lib/jsonapi/routing_ext.rb | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) diff --git a/lib/jsonapi/routing_ext.rb b/lib/jsonapi/routing_ext.rb index b0b94013..8302fc63 100644 --- a/lib/jsonapi/routing_ext.rb +++ b/lib/jsonapi/routing_ext.rb @@ -47,27 +47,14 @@ def jsonapi_resource(*resources, &_block) end resource @resource_type, options do - # :nocov: - if @scope.respond_to? :[]= - # Rails 4 - @scope[:jsonapi_resource] = @resource_type - + # Rails 6+ and 8.1: always use the modern block style + jsonapi_resource_scope(SingletonResource.new(@resource_type, api_only?, @scope[:shallow], options), @resource_type) do if block_given? yield else jsonapi_relationships end - else - # Rails 5 - jsonapi_resource_scope(SingletonResource.new(@resource_type, api_only?, @scope[:shallow], options), @resource_type) do - if block_given? - yield - else - jsonapi_relationships - end - end end - # :nocov: end end From c2f0662561d9f8454623c2be3e42f90ec2f1ee88 Mon Sep 17 00:00:00 2001 From: Dasun Pubudumal Date: Mon, 26 Jan 2026 11:32:40 +0000 Subject: [PATCH 02/16] Rails 8.1 fixes --- lib/jsonapi/routing_ext.rb | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) diff --git a/lib/jsonapi/routing_ext.rb b/lib/jsonapi/routing_ext.rb index 8302fc63..6e175384 100644 --- a/lib/jsonapi/routing_ext.rb +++ b/lib/jsonapi/routing_ext.rb @@ -86,7 +86,6 @@ def jsonapi_resources(*resources, &_block) options.merge!(res.routing_resource_options) options[:param] = :id - options[:path] = format_route(@resource_type) if res.resource_key_type == :uuid @@ -109,26 +108,14 @@ def jsonapi_resources(*resources, &_block) end resources @resource_type, options do - # :nocov: - if @scope.respond_to? :[]= - # Rails 4 - @scope[:jsonapi_resource] = @resource_type + # Rails 6+ and 8.1: always use the modern block style + jsonapi_resource_scope(Resource.new(@resource_type, api_only?, @scope[:shallow], options), @resource_type) do if block_given? yield else jsonapi_relationships end - else - # Rails 5 - jsonapi_resource_scope(Resource.new(@resource_type, api_only?, @scope[:shallow], options), @resource_type) do - if block_given? - yield - else - jsonapi_relationships - end - end end - # :nocov: end end From b80866e06267aef41a1a7e04b4bb5e3aa9f7e45b Mon Sep 17 00:00:00 2001 From: Dasun Pubudumal Date: Mon, 26 Jan 2026 11:36:03 +0000 Subject: [PATCH 03/16] Debugs --- lib/jsonapi/routing_ext.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/jsonapi/routing_ext.rb b/lib/jsonapi/routing_ext.rb index 6e175384..f3e91e77 100644 --- a/lib/jsonapi/routing_ext.rb +++ b/lib/jsonapi/routing_ext.rb @@ -107,6 +107,8 @@ def jsonapi_resources(*resources, &_block) options[:except] << :destroy unless options[:except].include?(:destroy) || options[:except].include?('destroy') end + p "Options: #{options}" + resources @resource_type, options do # Rails 6+ and 8.1: always use the modern block style jsonapi_resource_scope(Resource.new(@resource_type, api_only?, @scope[:shallow], options), @resource_type) do From 7086a630b9aa1952e572b4bbeeae14f8bc281414 Mon Sep 17 00:00:00 2001 From: Dasun Pubudumal Date: Mon, 26 Jan 2026 11:37:01 +0000 Subject: [PATCH 04/16] Debugs --- lib/jsonapi/routing_ext.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/jsonapi/routing_ext.rb b/lib/jsonapi/routing_ext.rb index f3e91e77..dbb18d7a 100644 --- a/lib/jsonapi/routing_ext.rb +++ b/lib/jsonapi/routing_ext.rb @@ -109,7 +109,7 @@ def jsonapi_resources(*resources, &_block) p "Options: #{options}" - resources @resource_type, options do + resources @resource_type, **options do # Rails 6+ and 8.1: always use the modern block style jsonapi_resource_scope(Resource.new(@resource_type, api_only?, @scope[:shallow], options), @resource_type) do if block_given? From 5b08066e0d3acb3c44ec8eaa514b7e58f8548051 Mon Sep 17 00:00:00 2001 From: Dasun Pubudumal Date: Mon, 26 Jan 2026 11:39:22 +0000 Subject: [PATCH 05/16] Debugs --- lib/jsonapi/routing_ext.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/jsonapi/routing_ext.rb b/lib/jsonapi/routing_ext.rb index dbb18d7a..6adbb0c1 100644 --- a/lib/jsonapi/routing_ext.rb +++ b/lib/jsonapi/routing_ext.rb @@ -46,7 +46,7 @@ def jsonapi_resource(*resources, &_block) options[:except] << :destroy unless options[:except].include?(:destroy) || options[:except].include?('destroy') end - resource @resource_type, options do + resource @resource_type, **options do # Rails 6+ and 8.1: always use the modern block style jsonapi_resource_scope(SingletonResource.new(@resource_type, api_only?, @scope[:shallow], options), @resource_type) do if block_given? From 2d152709cfc8b8b565b70b1bd1454dab85103d2e Mon Sep 17 00:00:00 2001 From: Dasun Pubudumal Date: Mon, 26 Jan 2026 11:41:27 +0000 Subject: [PATCH 06/16] Debugs --- lib/jsonapi/routing_ext.rb | 50 +++++++++++++++++++------------------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/lib/jsonapi/routing_ext.rb b/lib/jsonapi/routing_ext.rb index 6adbb0c1..937c2f83 100644 --- a/lib/jsonapi/routing_ext.rb +++ b/lib/jsonapi/routing_ext.rb @@ -33,18 +33,18 @@ def jsonapi_resource(*resources, &_block) options.merge!(res.routing_resource_options) options[:path] = format_route(@resource_type) - if options[:except] - options[:except] << :new unless options[:except].include?(:new) || options[:except].include?('new') - options[:except] << :edit unless options[:except].include?(:edit) || options[:except].include?('edit') - else - options[:except] = [:new, :edit] - end - - if res._immutable - options[:except] << :create unless options[:except].include?(:create) || options[:except].include?('create') - options[:except] << :update unless options[:except].include?(:update) || options[:except].include?('update') - options[:except] << :destroy unless options[:except].include?(:destroy) || options[:except].include?('destroy') - end + # if options[:except] + # options[:except] << :new unless options[:except].include?(:new) || options[:except].include?('new') + # options[:except] << :edit unless options[:except].include?(:edit) || options[:except].include?('edit') + # else + # options[:except] = [:new, :edit] + # end + + # if res._immutable + # options[:except] << :create unless options[:except].include?(:create) || options[:except].include?('create') + # options[:except] << :update unless options[:except].include?(:update) || options[:except].include?('update') + # options[:except] << :destroy unless options[:except].include?(:destroy) || options[:except].include?('destroy') + # end resource @resource_type, **options do # Rails 6+ and 8.1: always use the modern block style @@ -93,19 +93,19 @@ def jsonapi_resources(*resources, &_block) options[:constraints][:id] ||= /[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}/ end - if options[:except] - options[:except] = Array(options[:except]) - options[:except] << :new unless options[:except].include?(:new) || options[:except].include?('new') - options[:except] << :edit unless options[:except].include?(:edit) || options[:except].include?('edit') - else - options[:except] = [:new, :edit] - end - - if res._immutable - options[:except] << :create unless options[:except].include?(:create) || options[:except].include?('create') - options[:except] << :update unless options[:except].include?(:update) || options[:except].include?('update') - options[:except] << :destroy unless options[:except].include?(:destroy) || options[:except].include?('destroy') - end + # if options[:except] + # options[:except] = Array(options[:except]) + # options[:except] << :new unless options[:except].include?(:new) || options[:except].include?('new') + # options[:except] << :edit unless options[:except].include?(:edit) || options[:except].include?('edit') + # else + # options[:except] = [:new, :edit] + # end + + # if res._immutable + # options[:except] << :create unless options[:except].include?(:create) || options[:except].include?('create') + # options[:except] << :update unless options[:except].include?(:update) || options[:except].include?('update') + # options[:except] << :destroy unless options[:except].include?(:destroy) || options[:except].include?('destroy') + # end p "Options: #{options}" From 143cc1689ca677a23fc93762b3c6aff52c291fbe Mon Sep 17 00:00:00 2001 From: Dasun Pubudumal Date: Mon, 26 Jan 2026 11:46:48 +0000 Subject: [PATCH 07/16] Debugs --- lib/jsonapi/routing_ext.rb | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/jsonapi/routing_ext.rb b/lib/jsonapi/routing_ext.rb index 937c2f83..51070bf1 100644 --- a/lib/jsonapi/routing_ext.rb +++ b/lib/jsonapi/routing_ext.rb @@ -48,13 +48,13 @@ def jsonapi_resource(*resources, &_block) resource @resource_type, **options do # Rails 6+ and 8.1: always use the modern block style - jsonapi_resource_scope(SingletonResource.new(@resource_type, api_only?, @scope[:shallow], options), @resource_type) do - if block_given? - yield - else - jsonapi_relationships - end - end + # jsonapi_resource_scope(SingletonResource.new(@resource_type, api_only?, @scope[:shallow], options), @resource_type) do + # if block_given? + # yield + # else + # jsonapi_relationships + # end + # end end end From 4a7d6668b11cc35cfef73c8b172371145ea7dc4f Mon Sep 17 00:00:00 2001 From: Dasun Pubudumal Date: Mon, 26 Jan 2026 11:48:13 +0000 Subject: [PATCH 08/16] Debugs --- lib/jsonapi/routing_ext.rb | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/jsonapi/routing_ext.rb b/lib/jsonapi/routing_ext.rb index 51070bf1..49deafd7 100644 --- a/lib/jsonapi/routing_ext.rb +++ b/lib/jsonapi/routing_ext.rb @@ -46,7 +46,7 @@ def jsonapi_resource(*resources, &_block) # options[:except] << :destroy unless options[:except].include?(:destroy) || options[:except].include?('destroy') # end - resource @resource_type, **options do + resource @resource_type, options do # Rails 6+ and 8.1: always use the modern block style # jsonapi_resource_scope(SingletonResource.new(@resource_type, api_only?, @scope[:shallow], options), @resource_type) do # if block_given? @@ -109,15 +109,15 @@ def jsonapi_resources(*resources, &_block) p "Options: #{options}" - resources @resource_type, **options do + resources @resource_type, options do # Rails 6+ and 8.1: always use the modern block style - jsonapi_resource_scope(Resource.new(@resource_type, api_only?, @scope[:shallow], options), @resource_type) do - if block_given? - yield - else - jsonapi_relationships - end - end + # jsonapi_resource_scope(Resource.new(@resource_type, api_only?, @scope[:shallow], options), @resource_type) do + # if block_given? + # yield + # else + # jsonapi_relationships + # end + # end end end From 6f2d402d192e43b00f7c3f4631ad00f6f6349a86 Mon Sep 17 00:00:00 2001 From: Dasun Pubudumal Date: Mon, 26 Jan 2026 11:49:15 +0000 Subject: [PATCH 09/16] Debugs --- lib/jsonapi/routing_ext.rb | 50 +++++++++++++++++++------------------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/lib/jsonapi/routing_ext.rb b/lib/jsonapi/routing_ext.rb index 49deafd7..4c22ada0 100644 --- a/lib/jsonapi/routing_ext.rb +++ b/lib/jsonapi/routing_ext.rb @@ -33,18 +33,18 @@ def jsonapi_resource(*resources, &_block) options.merge!(res.routing_resource_options) options[:path] = format_route(@resource_type) - # if options[:except] - # options[:except] << :new unless options[:except].include?(:new) || options[:except].include?('new') - # options[:except] << :edit unless options[:except].include?(:edit) || options[:except].include?('edit') - # else - # options[:except] = [:new, :edit] - # end - - # if res._immutable - # options[:except] << :create unless options[:except].include?(:create) || options[:except].include?('create') - # options[:except] << :update unless options[:except].include?(:update) || options[:except].include?('update') - # options[:except] << :destroy unless options[:except].include?(:destroy) || options[:except].include?('destroy') - # end + if options[:except] + options[:except] << :new unless options[:except].include?(:new) || options[:except].include?('new') + options[:except] << :edit unless options[:except].include?(:edit) || options[:except].include?('edit') + else + options[:except] = [:new, :edit] + end + + if res._immutable + options[:except] << :create unless options[:except].include?(:create) || options[:except].include?('create') + options[:except] << :update unless options[:except].include?(:update) || options[:except].include?('update') + options[:except] << :destroy unless options[:except].include?(:destroy) || options[:except].include?('destroy') + end resource @resource_type, options do # Rails 6+ and 8.1: always use the modern block style @@ -93,19 +93,19 @@ def jsonapi_resources(*resources, &_block) options[:constraints][:id] ||= /[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}/ end - # if options[:except] - # options[:except] = Array(options[:except]) - # options[:except] << :new unless options[:except].include?(:new) || options[:except].include?('new') - # options[:except] << :edit unless options[:except].include?(:edit) || options[:except].include?('edit') - # else - # options[:except] = [:new, :edit] - # end - - # if res._immutable - # options[:except] << :create unless options[:except].include?(:create) || options[:except].include?('create') - # options[:except] << :update unless options[:except].include?(:update) || options[:except].include?('update') - # options[:except] << :destroy unless options[:except].include?(:destroy) || options[:except].include?('destroy') - # end + if options[:except] + options[:except] = Array(options[:except]) + options[:except] << :new unless options[:except].include?(:new) || options[:except].include?('new') + options[:except] << :edit unless options[:except].include?(:edit) || options[:except].include?('edit') + else + options[:except] = [:new, :edit] + end + + if res._immutable + options[:except] << :create unless options[:except].include?(:create) || options[:except].include?('create') + options[:except] << :update unless options[:except].include?(:update) || options[:except].include?('update') + options[:except] << :destroy unless options[:except].include?(:destroy) || options[:except].include?('destroy') + end p "Options: #{options}" From 5465f91856f4bc40c97246ec2ed06073e6becdbe Mon Sep 17 00:00:00 2001 From: Dasun Pubudumal Date: Mon, 26 Jan 2026 12:28:49 +0000 Subject: [PATCH 10/16] Debugs --- lib/jsonapi/routing_ext.rb | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/lib/jsonapi/routing_ext.rb b/lib/jsonapi/routing_ext.rb index 4c22ada0..7e6366c1 100644 --- a/lib/jsonapi/routing_ext.rb +++ b/lib/jsonapi/routing_ext.rb @@ -107,17 +107,14 @@ def jsonapi_resources(*resources, &_block) options[:except] << :destroy unless options[:except].include?(:destroy) || options[:except].include?('destroy') end - p "Options: #{options}" - resources @resource_type, options do # Rails 6+ and 8.1: always use the modern block style - # jsonapi_resource_scope(Resource.new(@resource_type, api_only?, @scope[:shallow], options), @resource_type) do - # if block_given? - # yield - # else - # jsonapi_relationships - # end - # end + @jsonapi_resource_type = @resource_type + if block_given? + yield + else + jsonapi_relationships + end end end From 71b84c2e56cf1de9b07dadad01de4a6e49b5040a Mon Sep 17 00:00:00 2001 From: Dasun Pubudumal Date: Mon, 26 Jan 2026 12:30:30 +0000 Subject: [PATCH 11/16] Debugs --- lib/jsonapi/routing_ext.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/jsonapi/routing_ext.rb b/lib/jsonapi/routing_ext.rb index 7e6366c1..a7d5048f 100644 --- a/lib/jsonapi/routing_ext.rb +++ b/lib/jsonapi/routing_ext.rb @@ -109,7 +109,6 @@ def jsonapi_resources(*resources, &_block) resources @resource_type, options do # Rails 6+ and 8.1: always use the modern block style - @jsonapi_resource_type = @resource_type if block_given? yield else From bde2c2a085f22523685c9de4bd852a730de7b846 Mon Sep 17 00:00:00 2001 From: Dasun Pubudumal Date: Mon, 26 Jan 2026 13:04:20 +0000 Subject: [PATCH 12/16] Rails 8.1 compatibility fix --- lib/jsonapi/routing_ext.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/jsonapi/routing_ext.rb b/lib/jsonapi/routing_ext.rb index a7d5048f..c46aef32 100644 --- a/lib/jsonapi/routing_ext.rb +++ b/lib/jsonapi/routing_ext.rb @@ -109,11 +109,13 @@ def jsonapi_resources(*resources, &_block) resources @resource_type, options do # Rails 6+ and 8.1: always use the modern block style + jsonapi_resource_scope(Resource.new(@resource_type, api_only?, @scope[:shallow], **options), @resource_type) do if block_given? yield else jsonapi_relationships end + end end end From fe5f506922fe42ef279fd67d12b0d4064fcb2f69 Mon Sep 17 00:00:00 2001 From: Dasun Pubudumal Date: Mon, 26 Jan 2026 13:13:48 +0000 Subject: [PATCH 13/16] Refactor routing_ext.rb to use modern block style for resource handling --- lib/jsonapi/routing_ext.rb | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/lib/jsonapi/routing_ext.rb b/lib/jsonapi/routing_ext.rb index c46aef32..2f2de0d3 100644 --- a/lib/jsonapi/routing_ext.rb +++ b/lib/jsonapi/routing_ext.rb @@ -47,14 +47,13 @@ def jsonapi_resource(*resources, &_block) end resource @resource_type, options do - # Rails 6+ and 8.1: always use the modern block style - # jsonapi_resource_scope(SingletonResource.new(@resource_type, api_only?, @scope[:shallow], options), @resource_type) do - # if block_given? - # yield - # else - # jsonapi_relationships - # end - # end + jsonapi_resource_scope(SingletonResource.new(@resource_type, api_only?, @scope[:shallow], options), @resource_type) do + if block_given? + yield + else + jsonapi_relationships + end + end end end From 928771a62476c88f0af4fa25b7238016a037f269 Mon Sep 17 00:00:00 2001 From: Dasun Pubudumal Date: Mon, 26 Jan 2026 13:14:16 +0000 Subject: [PATCH 14/16] Refactor routing_ext.rb to use modern block style for resource handling --- lib/jsonapi/routing_ext.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/jsonapi/routing_ext.rb b/lib/jsonapi/routing_ext.rb index 2f2de0d3..52995a33 100644 --- a/lib/jsonapi/routing_ext.rb +++ b/lib/jsonapi/routing_ext.rb @@ -47,7 +47,7 @@ def jsonapi_resource(*resources, &_block) end resource @resource_type, options do - jsonapi_resource_scope(SingletonResource.new(@resource_type, api_only?, @scope[:shallow], options), @resource_type) do + jsonapi_resource_scope(SingletonResource.new(@resource_type, api_only?, @scope[:shallow], **options), @resource_type) do if block_given? yield else From 4c72d7f0dd7942a42d2fcc902c1854c8d2065f8a Mon Sep 17 00:00:00 2001 From: Dasun Pubudumal Date: Mon, 26 Jan 2026 13:23:54 +0000 Subject: [PATCH 15/16] Refactor routing_ext.rb to handle Rails version compatibility in resource handling --- lib/jsonapi/routing_ext.rb | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/lib/jsonapi/routing_ext.rb b/lib/jsonapi/routing_ext.rb index 52995a33..2bc480fe 100644 --- a/lib/jsonapi/routing_ext.rb +++ b/lib/jsonapi/routing_ext.rb @@ -47,13 +47,27 @@ def jsonapi_resource(*resources, &_block) end resource @resource_type, options do - jsonapi_resource_scope(SingletonResource.new(@resource_type, api_only?, @scope[:shallow], **options), @resource_type) do + # :nocov: + if @scope.respond_to? :[]= + # Rails 4 + @scope[:jsonapi_resource] = @resource_type + if block_given? yield else jsonapi_relationships end + else + # Rails 5 + jsonapi_resource_scope(SingletonResource.new(@resource_type, api_only?, @scope[:shallow], **options), @resource_type) do + if block_given? + yield + else + jsonapi_relationships + end + end end + # :nocov: end end @@ -85,6 +99,7 @@ def jsonapi_resources(*resources, &_block) options.merge!(res.routing_resource_options) options[:param] = :id + options[:path] = format_route(@resource_type) if res.resource_key_type == :uuid @@ -107,14 +122,26 @@ def jsonapi_resources(*resources, &_block) end resources @resource_type, options do - # Rails 6+ and 8.1: always use the modern block style - jsonapi_resource_scope(Resource.new(@resource_type, api_only?, @scope[:shallow], **options), @resource_type) do + # :nocov: + if @scope.respond_to? :[]= + # Rails 4 + @scope[:jsonapi_resource] = @resource_type if block_given? yield else jsonapi_relationships end + else + # Rails 5 + jsonapi_resource_scope(Resource.new(@resource_type, api_only?, @scope[:shallow], **options), @resource_type) do + if block_given? + yield + else + jsonapi_relationships + end + end end + # :nocov: end end From cc52b3bb599c9361ca76cba3133b42aebdb2d3af Mon Sep 17 00:00:00 2001 From: Dasun Pubudumal Date: Mon, 26 Jan 2026 13:27:02 +0000 Subject: [PATCH 16/16] Bump version to 0.3.0 --- lib/jsonapi/resources/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/jsonapi/resources/version.rb b/lib/jsonapi/resources/version.rb index ae4b3a9d..b25e5b70 100644 --- a/lib/jsonapi/resources/version.rb +++ b/lib/jsonapi/resources/version.rb @@ -1,5 +1,5 @@ module JSONAPI module Resources - VERSION = '0.2.1' + VERSION = '0.3.0' end end