@@ -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
121124end
0 commit comments