From 5b0066cc7cb80b920d5b59e9577c271f7c692855 Mon Sep 17 00:00:00 2001 From: Eric Proulx <eproulx@petalmd.com> Date: Tue, 1 Oct 2024 22:21:11 +0200 Subject: [PATCH] Remove deprecation msg + small refactor (#2502) * Remove deprecation msg + small refactor * Add CHANGELOG.md and UPGRADING.md --- CHANGELOG.md | 1 + UPGRADING.md | 3 +++ lib/grape/dsl/desc.rb | 51 ++++++++++++++++++++----------------- spec/grape/dsl/desc_spec.rb | 13 ---------- 4 files changed, 31 insertions(+), 37 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 14f5ce81f1..344f349341 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ * [#2497](https://github.com/ruby-grape/grape/pull/2497): Update RuboCop to 1.66.1 - [@ericproulx](https://github.com/ericproulx). * [#2500](https://github.com/ruby-grape/grape/pull/2500): Remove deprecated `file` method - [@ericproulx](https://github.com/ericproulx). * [#2501](https://github.com/ruby-grape/grape/pull/2501): Remove deprecated `except` and `proc` options in values validator - [@ericproulx](https://github.com/ericproulx). +* [#2502](https://github.com/ruby-grape/grape/pull/2502): Remove deprecation `options` in `desc` - [@ericproulx](https://github.com/ericproulx). * Your contribution here. #### Fixes diff --git a/UPGRADING.md b/UPGRADING.md index 8039f3af5a..ab80fe4cb4 100644 --- a/UPGRADING.md +++ b/UPGRADING.md @@ -11,6 +11,9 @@ See [#2500](https://github.com/ruby-grape/grape/pull/2500) for more information. - The `except` and `proc` options have been removed from the `values` validator. Use `except_values` validator or assign `proc` directly to `values`. See [#2501](https://github.com/ruby-grape/grape/pull/2501) for more information. +- `Passing an options hash and a block to 'desc'` deprecation has been removed. Move all hash options to block instead. +See [#2502](https://github.com/ruby-grape/grape/pull/2502) for more information. + ### Upgrading to >= 2.2.0 ### `Length` validator diff --git a/lib/grape/dsl/desc.rb b/lib/grape/dsl/desc.rb index f83eb8b004..2d31550269 100644 --- a/lib/grape/dsl/desc.rb +++ b/lib/grape/dsl/desc.rb @@ -70,33 +70,23 @@ module Desc # # ... # end # - def desc(description, options = {}, &config_block) - if config_block - endpoint_configuration = if defined?(configuration) - # When the instance is mounted - the configuration is executed on mount time - if configuration.respond_to?(:evaluate) - configuration.evaluate - # Within `given` or `mounted blocks` the configuration is already evaluated - elsif configuration.is_a?(Hash) - configuration - end - end - endpoint_configuration ||= {} - config_class = desc_container(endpoint_configuration) + def desc(description, options = nil, &config_block) + opts = + if config_block + desc_container(endpoint_configuration).then do |config_class| + config_class.configure do + description(description) + end - config_class.configure do - description description + config_class.configure(&config_block) + config_class.settings + end + else + options&.merge(description: description) || { description: description } end - config_class.configure(&config_block) - Grape.deprecator.warn('Passing a options hash and a block to `desc` is deprecated. Move all hash options to block.') if options.any? - options = config_class.settings - else - options = options.merge(description: description) - end - - namespace_setting :description, options - route_setting :description, options + namespace_setting :description, opts + route_setting :description, opts end # Returns an object which configures itself via an instance-context DSL. @@ -116,6 +106,19 @@ def config_context.failure(*args) end end end + + private + + def endpoint_configuration + return {} unless defined?(configuration) + + if configuration.respond_to?(:evaluate) + configuration.evaluate + # Within `given` or `mounted blocks` the configuration is already evaluated + elsif configuration.is_a?(Hash) + configuration + end + end end end end diff --git a/spec/grape/dsl/desc_spec.rb b/spec/grape/dsl/desc_spec.rb index fa3ae7f9ea..aa2aa4c333 100644 --- a/spec/grape/dsl/desc_spec.rb +++ b/spec/grape/dsl/desc_spec.rb @@ -81,18 +81,5 @@ expect(subject.namespace_setting(:description)).to eq(expected_options) expect(subject.route_setting(:description)).to eq(expected_options) end - - it 'can be set with options and a block' do - expect(Grape.deprecator).to receive(:warn).with('Passing a options hash and a block to `desc` is deprecated. Move all hash options to block.') - - desc_text = 'The description' - detail_text = 'more details' - options = { message: 'none' } - subject.desc desc_text, options do - detail detail_text - end - expect(subject.namespace_setting(:description)).to eq(description: desc_text, detail: detail_text) - expect(subject.route_setting(:description)).to eq(description: desc_text, detail: detail_text) - end end end