@@ -6,91 +6,9 @@ module Configuration
6
6
extend ActiveSupport ::Concern
7
7
8
8
module ClassMethods
9
- attr_writer :logger
10
-
11
9
include Grape ::DSL ::Settings
12
-
13
- # Set or retrive the configured logger. If none was configured, this
14
- # method will create a new one, logging to stdout.
15
- # @param logger [Object] the new logger to use
16
- def logger ( logger = nil )
17
- if logger
18
- global_setting ( :logger , logger )
19
- else
20
- global_setting ( :logger ) || global_setting ( :logger , Logger . new ( $stdout) )
21
- end
22
- end
23
-
24
- # Add a description to the next namespace or function.
25
- # @param description [String] descriptive string for this endpoint
26
- # or namespace
27
- # @param options [Hash] other properties you can set to describe the
28
- # endpoint or namespace. Optional.
29
- # @option options :detail [String] additional detail about this endpoint
30
- # @option options :params [Hash] param types and info. normally, you set
31
- # these via the `params` dsl method.
32
- # @option options :entity [Grape::Entity] the entity returned upon a
33
- # successful call to this action
34
- # @option options :http_codes [Array[Array]] possible HTTP codes this
35
- # endpoint may return, with their meanings, in a 2d array
36
- # @option options :named [String] a specific name to help find this route
37
- # @option options :headers [Hash] HTTP headers this method can accept
38
- # @yield a block yielding an instance context with methods mapping to
39
- # each of the above, except that :entity is also aliased as #success
40
- # and :http_codes is aliased as #failure.
41
- #
42
- # @example
43
- #
44
- # desc 'create a user'
45
- # post '/users' do
46
- # # ...
47
- # end
48
- #
49
- # desc 'find a user' do
50
- # detail 'locates the user from the given user ID'
51
- # failure [ [404, 'Couldn\'t find the given user' ] ]
52
- # success User::Entity
53
- # end
54
- # get '/user/:id' do
55
- # # ...
56
- # end
57
- #
58
- def desc ( description , options = { } , &config_block )
59
- if block_given?
60
- config_class = Grape ::DSL ::Configuration . desc_container
61
-
62
- config_class . configure do
63
- description description
64
- end
65
-
66
- config_class . configure ( &config_block )
67
- unless options . empty?
68
- warn '[DEPRECATION] Passing a options hash and a block to `desc` is deprecated. Move all hash options to block.'
69
- end
70
- options = config_class . settings
71
- else
72
- options = options . merge ( description : description )
73
- end
74
-
75
- namespace_setting :description , options
76
- route_setting :description , options
77
- end
78
-
79
- def description_field ( field , value = nil )
80
- if value
81
- description = route_setting ( :description )
82
- description ||= route_setting ( :description , { } )
83
- description [ field ] = value
84
- else
85
- description = route_setting ( :description )
86
- description [ field ] if description
87
- end
88
- end
89
-
90
- def unset_description_field ( field )
91
- description = route_setting ( :description )
92
- description . delete ( field ) if description
93
- end
10
+ include Grape ::DSL ::Logger
11
+ include Grape ::DSL ::Desc
94
12
end
95
13
96
14
module_function
@@ -100,29 +18,6 @@ def stacked_hash_to_hash(settings)
100
18
return if settings . blank?
101
19
settings . each_with_object ( { } ) { |value , result | result . deep_merge! ( value ) }
102
20
end
103
-
104
- # Returns an object which configures itself via an instance-context DSL.
105
- def desc_container
106
- Module . new do
107
- include Grape ::Util ::StrictHashConfiguration . module (
108
- :description ,
109
- :detail ,
110
- :params ,
111
- :entity ,
112
- :http_codes ,
113
- :named ,
114
- :headers
115
- )
116
-
117
- def config_context . success ( *args )
118
- entity ( *args )
119
- end
120
-
121
- def config_context . failure ( *args )
122
- http_codes ( *args )
123
- end
124
- end
125
- end
126
21
end
127
22
end
128
23
end
0 commit comments