From 13528b41596673b33e3480fad8b511774f336d5c Mon Sep 17 00:00:00 2001 From: Eric Date: Tue, 1 Oct 2024 14:18:13 +0200 Subject: [PATCH] Remove deprecation msg + small refactor --- lib/grape/dsl/desc.rb | 51 ++++++++++++++++++++----------------- spec/grape/dsl/desc_spec.rb | 13 ---------- 2 files changed, 27 insertions(+), 37 deletions(-) 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