@@ -70,33 +70,23 @@ module Desc
70
70
# # ...
71
71
# end
72
72
#
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
86
80
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 }
89
86
end
90
87
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
100
90
end
101
91
102
92
# Returns an object which configures itself via an instance-context DSL.
@@ -116,6 +106,19 @@ def config_context.failure(*args)
116
106
end
117
107
end
118
108
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
119
122
end
120
123
end
121
124
end
0 commit comments