From 6fdad1f2a83b65784948a0bb78c5078ed43839cd Mon Sep 17 00:00:00 2001 From: Eric Proulx Date: Sat, 20 Dec 2025 20:39:24 +0000 Subject: [PATCH] Remove deprecated params_builder extensions. --- CHANGELOG.md | 1 + UPGRADING.md | 7 ++++ lib/grape.rb | 1 - .../hash_with_indifferent_access.rb | 24 ------------ lib/grape/extensions/hash.rb | 27 ------------- lib/grape/extensions/hashie/mash.rb | 24 ------------ lib/grape/params_builder.rb | 21 +--------- .../extensions/param_builders/hash_spec.rb | 38 ------------------- .../hash_with_indifferent_access_spec.rb | 38 ------------------- spec/integration/hashie/hashie_spec.rb | 38 ------------------- 10 files changed, 10 insertions(+), 209 deletions(-) delete mode 100644 lib/grape/extensions/active_support/hash_with_indifferent_access.rb delete mode 100644 lib/grape/extensions/hash.rb delete mode 100644 lib/grape/extensions/hashie/mash.rb delete mode 100644 spec/grape/extensions/param_builders/hash_spec.rb delete mode 100644 spec/grape/extensions/param_builders/hash_with_indifferent_access_spec.rb diff --git a/CHANGELOG.md b/CHANGELOG.md index 30074b603..84225efb9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ * [#2643](https://github.com/ruby-grape/grape/pull/2638): Remove `try` method in codebase - [@ericproulx](https://github.com/ericproulx). * [#2646](https://github.com/ruby-grape/grape/pull/2646): Call `valid_encoding?` before scrub - [@ericproulx](https://github.com/ericproulx). * [#2644](https://github.com/ruby-grape/grape/pull/2644): Clean useless/not valuable dependencies - [@ericproulx](https://github.com/ericproulx). +* [#2648](https://github.com/ruby-grape/grape/pull/2648): Remove deprecated ParamsBuilders extensions - [@ericproulx](https://github.com/ericproulx). * Your contribution here. #### Fixes diff --git a/UPGRADING.md b/UPGRADING.md index 1e6b1b991..4975e553f 100644 --- a/UPGRADING.md +++ b/UPGRADING.md @@ -1,6 +1,13 @@ Upgrading Grape =============== +### Upgrading to >= 3.1 + +#### ParamsBuilder Grape::Extensions + +Deprecated [ParamsBuilder's extensions](https://github.com/ruby-grape/grape/blob/master/UPGRADING.md#params-builder) has been removed from the code base. + + ### Upgrading to >= 3.0.0 #### Ruby 3+ Argument Delegation Modernization diff --git a/lib/grape.rb b/lib/grape.rb index 9deb8d383..ac1f9e8af 100644 --- a/lib/grape.rb +++ b/lib/grape.rb @@ -2,7 +2,6 @@ require 'logger' require 'active_support' -require 'active_support/concern' require 'active_support/version' require 'active_support/isolated_execution_state' require 'active_support/core_ext/array/conversions' # to_xml diff --git a/lib/grape/extensions/active_support/hash_with_indifferent_access.rb b/lib/grape/extensions/active_support/hash_with_indifferent_access.rb deleted file mode 100644 index c90b734b7..000000000 --- a/lib/grape/extensions/active_support/hash_with_indifferent_access.rb +++ /dev/null @@ -1,24 +0,0 @@ -# frozen_string_literal: true - -module Grape - module Extensions - module ActiveSupport - module HashWithIndifferentAccess - module ParamBuilder - extend ::ActiveSupport::Concern - - included do - Grape.deprecator.warn 'This concern has been deprecated. Use `build_with` with one of the following short_name (:hash, :hash_with_indifferent_access, :hashie_mash) instead.' - namespace_inheritable(:build_params_with, :hash_with_indifferent_access) - end - - def build_params - ::ActiveSupport::HashWithIndifferentAccess.new(rack_params).tap do |params| - params.deep_merge!(grape_routing_args) if env.key?(Grape::Env::GRAPE_ROUTING_ARGS) - end - end - end - end - end - end -end diff --git a/lib/grape/extensions/hash.rb b/lib/grape/extensions/hash.rb deleted file mode 100644 index 6d5ef6e65..000000000 --- a/lib/grape/extensions/hash.rb +++ /dev/null @@ -1,27 +0,0 @@ -# frozen_string_literal: true - -module Grape - module Extensions - module Hash - module ParamBuilder - extend ::ActiveSupport::Concern - - included do - Grape.deprecator.warn 'This concern has been deprecated. Use `build_with` with one of the following short_name (:hash, :hash_with_indifferent_access, :hashie_mash) instead.' - namespace_inheritable(:build_params_with, :hash) - end - - def build_params - rack_params.deep_dup.tap do |params| - params.deep_symbolize_keys! - - if env.key?(Grape::Env::GRAPE_ROUTING_ARGS) - grape_routing_args.deep_symbolize_keys! - params.deep_merge!(grape_routing_args) - end - end - end - end - end - end -end diff --git a/lib/grape/extensions/hashie/mash.rb b/lib/grape/extensions/hashie/mash.rb deleted file mode 100644 index c144b4fd2..000000000 --- a/lib/grape/extensions/hashie/mash.rb +++ /dev/null @@ -1,24 +0,0 @@ -# frozen_string_literal: true - -module Grape - module Extensions - module Hashie - module Mash - module ParamBuilder - extend ::ActiveSupport::Concern - - included do - Grape.deprecator.warn 'This concern has been deprecated. Use `build_with` with one of the following short_name (:hash, :hash_with_indifferent_access, :hashie_mash) instead.' - namespace_inheritable(:build_params_with, :hashie_mash) - end - - def build_params - ::Hashie::Mash.new(rack_params).tap do |params| - params.deep_merge!(grape_routing_args) if env.key?(Grape::Env::GRAPE_ROUTING_ARGS) - end - end - end - end - end - end -end diff --git a/lib/grape/params_builder.rb b/lib/grape/params_builder.rb index 03cd9d1e3..989aae2bf 100644 --- a/lib/grape/params_builder.rb +++ b/lib/grape/params_builder.rb @@ -4,29 +4,12 @@ module Grape module ParamsBuilder extend Grape::Util::Registry - SHORT_NAME_LOOKUP = { - 'Grape::Extensions::Hash::ParamBuilder' => :hash, - 'Grape::Extensions::ActiveSupport::HashWithIndifferentAccess::ParamBuilder' => :hash_with_indifferent_access, - 'Grape::Extensions::Hashie::Mash::ParamBuilder' => :hashie_mash - }.freeze - module_function def params_builder_for(short_name) - verified_short_name = verify_short_name!(short_name) - - raise Grape::Exceptions::UnknownParamsBuilder, verified_short_name unless registry.key?(verified_short_name) - - registry[verified_short_name] - end - - def verify_short_name!(short_name) - return short_name if short_name.is_a?(Symbol) + raise Grape::Exceptions::UnknownParamsBuilder, short_name unless registry.key?(short_name) - class_name = short_name.name - SHORT_NAME_LOOKUP[class_name].tap do |real_short_name| - Grape.deprecator.warn "#{class_name} has been deprecated. Use short name :#{real_short_name} instead." - end + registry[short_name] end end end diff --git a/spec/grape/extensions/param_builders/hash_spec.rb b/spec/grape/extensions/param_builders/hash_spec.rb deleted file mode 100644 index d4bc7b784..000000000 --- a/spec/grape/extensions/param_builders/hash_spec.rb +++ /dev/null @@ -1,38 +0,0 @@ -# frozen_string_literal: true - -describe Grape::Extensions::Hash::ParamBuilder do - describe 'deprecation' do - context 'when included' do - subject do - Class.new(Grape::API) do - include Grape::Extensions::Hash::ParamBuilder - end - end - - let(:message) do - 'This concern has been deprecated. Use `build_with` with one of the following short_name (:hash, :hash_with_indifferent_access, :hashie_mash) instead.' - end - - it 'raises a deprecation' do - expect(Grape.deprecator).to receive(:warn).with(message).and_raise(ActiveSupport::DeprecationException, :deprecated) - expect { subject }.to raise_error(ActiveSupport::DeprecationException, 'deprecated') - end - end - - context 'when using class name' do - let(:app) do - Class.new(Grape::API) do - params do - build_with Grape::Extensions::Hash::ParamBuilder - end - get - end - end - - it 'raises a deprecation' do - expect(Grape.deprecator).to receive(:warn).with("#{described_class} has been deprecated. Use short name :hash instead.").and_raise(ActiveSupport::DeprecationException, :deprecated) - expect { get '/' }.to raise_error(ActiveSupport::DeprecationException, 'deprecated') - end - end - end -end diff --git a/spec/grape/extensions/param_builders/hash_with_indifferent_access_spec.rb b/spec/grape/extensions/param_builders/hash_with_indifferent_access_spec.rb deleted file mode 100644 index 86ae1c84a..000000000 --- a/spec/grape/extensions/param_builders/hash_with_indifferent_access_spec.rb +++ /dev/null @@ -1,38 +0,0 @@ -# frozen_string_literal: true - -describe Grape::Extensions::ActiveSupport::HashWithIndifferentAccess::ParamBuilder do - describe 'deprecation' do - context 'when included' do - subject do - Class.new(Grape::API) do - include Grape::Extensions::ActiveSupport::HashWithIndifferentAccess::ParamBuilder - end - end - - let(:message) do - 'This concern has been deprecated. Use `build_with` with one of the following short_name (:hash, :hash_with_indifferent_access, :hashie_mash) instead.' - end - - it 'raises a deprecation' do - expect(Grape.deprecator).to receive(:warn).with(message).and_raise(ActiveSupport::DeprecationException, :deprecated) - expect { subject }.to raise_error(ActiveSupport::DeprecationException, 'deprecated') - end - end - end - - context 'when using class name' do - let(:app) do - Class.new(Grape::API) do - params do - build_with Grape::Extensions::ActiveSupport::HashWithIndifferentAccess::ParamBuilder - end - get - end - end - - it 'raises a deprecation' do - expect(Grape.deprecator).to receive(:warn).with("#{described_class} has been deprecated. Use short name :hash_with_indifferent_access instead.").and_raise(ActiveSupport::DeprecationException, :deprecated) - expect { get '/' }.to raise_error(ActiveSupport::DeprecationException, 'deprecated') - end - end -end diff --git a/spec/integration/hashie/hashie_spec.rb b/spec/integration/hashie/hashie_spec.rb index 8d9021c6d..b617aa0e9 100644 --- a/spec/integration/hashie/hashie_spec.rb +++ b/spec/integration/hashie/hashie_spec.rb @@ -5,44 +5,6 @@ let(:app) { Class.new(Grape::API) } - describe 'Grape::Extensions::Hashie::Mash::ParamBuilder' do - describe 'deprecation' do - context 'when included' do - subject do - Class.new(Grape::API) do - include Grape::Extensions::Hashie::Mash::ParamBuilder - end - end - - let(:message) do - 'This concern has been deprecated. Use `build_with` with one of the following short_name (:hash, :hash_with_indifferent_access, :hashie_mash) instead.' - end - - it 'raises a deprecation' do - expect(Grape.deprecator).to receive(:warn).with(message).and_raise(ActiveSupport::DeprecationException, :deprecated) - expect { subject }.to raise_error(ActiveSupport::DeprecationException, 'deprecated') - end - end - - context 'when using class name' do - let(:app) do - Class.new(Grape::API) do - params do - build_with Grape::Extensions::Hashie::Mash::ParamBuilder - end - get - end - end - - it 'raises a deprecation' do - expect(Grape.deprecator).to receive(:warn).with('Grape::Extensions::Hashie::Mash::ParamBuilder has been deprecated. Use short name :hashie_mash instead.').and_raise(ActiveSupport::DeprecationException, - :deprecated) - expect { get '/' }.to raise_error(ActiveSupport::DeprecationException, 'deprecated') - end - end - end - end - describe 'Grape::ParamsBuilder::HashieMash' do describe 'in an endpoint' do describe '#params' do