Skip to content

Commit 5b0066c

Browse files
authored
Remove deprecation msg + small refactor (#2502)
* Remove deprecation msg + small refactor * Add CHANGELOG.md and UPGRADING.md
1 parent 7f0595c commit 5b0066c

File tree

4 files changed

+31
-37
lines changed

4 files changed

+31
-37
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
* [#2497](https://github.com/ruby-grape/grape/pull/2497): Update RuboCop to 1.66.1 - [@ericproulx](https://github.com/ericproulx).
66
* [#2500](https://github.com/ruby-grape/grape/pull/2500): Remove deprecated `file` method - [@ericproulx](https://github.com/ericproulx).
77
* [#2501](https://github.com/ruby-grape/grape/pull/2501): Remove deprecated `except` and `proc` options in values validator - [@ericproulx](https://github.com/ericproulx).
8+
* [#2502](https://github.com/ruby-grape/grape/pull/2502): Remove deprecation `options` in `desc` - [@ericproulx](https://github.com/ericproulx).
89
* Your contribution here.
910

1011
#### Fixes

UPGRADING.md

+3
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ See [#2500](https://github.com/ruby-grape/grape/pull/2500) for more information.
1111
- The `except` and `proc` options have been removed from the `values` validator. Use `except_values` validator or assign `proc` directly to `values`.
1212
See [#2501](https://github.com/ruby-grape/grape/pull/2501) for more information.
1313

14+
- `Passing an options hash and a block to 'desc'` deprecation has been removed. Move all hash options to block instead.
15+
See [#2502](https://github.com/ruby-grape/grape/pull/2502) for more information.
16+
1417
### Upgrading to >= 2.2.0
1518

1619
### `Length` validator

lib/grape/dsl/desc.rb

+27-24
Original file line numberDiff line numberDiff line change
@@ -70,33 +70,23 @@ module Desc
7070
# # ...
7171
# end
7272
#
73-
def desc(description, options = {}, &config_block)
74-
if config_block
75-
endpoint_configuration = if defined?(configuration)
76-
# When the instance is mounted - the configuration is executed on mount time
77-
if configuration.respond_to?(:evaluate)
78-
configuration.evaluate
79-
# Within `given` or `mounted blocks` the configuration is already evaluated
80-
elsif configuration.is_a?(Hash)
81-
configuration
82-
end
83-
end
84-
endpoint_configuration ||= {}
85-
config_class = desc_container(endpoint_configuration)
73+
def desc(description, options = nil, &config_block)
74+
opts =
75+
if config_block
76+
desc_container(endpoint_configuration).then do |config_class|
77+
config_class.configure do
78+
description(description)
79+
end
8680

87-
config_class.configure do
88-
description description
81+
config_class.configure(&config_block)
82+
config_class.settings
83+
end
84+
else
85+
options&.merge(description: description) || { description: description }
8986
end
9087

91-
config_class.configure(&config_block)
92-
Grape.deprecator.warn('Passing a options hash and a block to `desc` is deprecated. Move all hash options to block.') if options.any?
93-
options = config_class.settings
94-
else
95-
options = options.merge(description: description)
96-
end
97-
98-
namespace_setting :description, options
99-
route_setting :description, options
88+
namespace_setting :description, opts
89+
route_setting :description, opts
10090
end
10191

10292
# Returns an object which configures itself via an instance-context DSL.
@@ -116,6 +106,19 @@ def config_context.failure(*args)
116106
end
117107
end
118108
end
109+
110+
private
111+
112+
def endpoint_configuration
113+
return {} unless defined?(configuration)
114+
115+
if configuration.respond_to?(:evaluate)
116+
configuration.evaluate
117+
# Within `given` or `mounted blocks` the configuration is already evaluated
118+
elsif configuration.is_a?(Hash)
119+
configuration
120+
end
121+
end
119122
end
120123
end
121124
end

spec/grape/dsl/desc_spec.rb

-13
Original file line numberDiff line numberDiff line change
@@ -81,18 +81,5 @@
8181
expect(subject.namespace_setting(:description)).to eq(expected_options)
8282
expect(subject.route_setting(:description)).to eq(expected_options)
8383
end
84-
85-
it 'can be set with options and a block' do
86-
expect(Grape.deprecator).to receive(:warn).with('Passing a options hash and a block to `desc` is deprecated. Move all hash options to block.')
87-
88-
desc_text = 'The description'
89-
detail_text = 'more details'
90-
options = { message: 'none' }
91-
subject.desc desc_text, options do
92-
detail detail_text
93-
end
94-
expect(subject.namespace_setting(:description)).to eq(description: desc_text, detail: detail_text)
95-
expect(subject.route_setting(:description)).to eq(description: desc_text, detail: detail_text)
96-
end
9784
end
9885
end

0 commit comments

Comments
 (0)