Module: ApipieDSL::Method
Constant Summary
Constants included
from Parameter
Parameter::SUPPORTED_TYPES
Instance Method Summary
collapse
-
#aliases(*names) ⇒ Object
-
#example(example, desc_or_options = nil, options = {}) ⇒ Object
-
#example_for(method_name, example, desc_or_options = nil, options = {}) ⇒ Object
-
#method(name, desc = nil, _options = {}) ⇒ Object
-
#raises(error_or_options, desc = nil, options = {}) ⇒ Object
Describe possible errors.
-
#returns(retobj_or_options, desc_or_options = nil, options = {}, &block) ⇒ Object
-
#see(method, options = {}) ⇒ Object
Reference other similar method.
-
#signature(*signature) ⇒ Object
Methods included from Parameter
#block, #default_param_group_scope, #define_param_group, #keyword, #list, #optional, #param, #param_group, #required
Instance Method Details
#aliases(*names) ⇒ Object
174
175
176
|
# File 'lib/apipie_dsl/dsl.rb', line 174
def aliases(*names)
dsl_data[:aliases] = names
end
|
#example(example, desc_or_options = nil, options = {}) ⇒ Object
233
234
235
236
237
238
239
240
|
# File 'lib/apipie_dsl/dsl.rb', line 233
def example(example, desc_or_options = nil, options = {})
if desc_or_options.is_a?(Hash)
options.merge!(desc_or_options)
elsif !desc_or_options.nil?
options[:desc] = desc_or_options
end
dsl_data[:examples] << { example: example, desc: options[:desc], for: options[:for] }
end
|
#example_for(method_name, example, desc_or_options = nil, options = {}) ⇒ Object
242
243
244
245
246
247
248
249
|
# File 'lib/apipie_dsl/dsl.rb', line 242
def example_for(method_name, example, desc_or_options = nil, options = {})
if desc_or_options.is_a?(Hash)
options.merge!(desc_or_options)
elsif !desc_or_options.nil?
options[:desc] = desc_or_options
end
dsl_data[:examples] << { example: example, desc: options[:desc], for: method_name }
end
|
#method(name, desc = nil, _options = {}) ⇒ Object
169
170
171
172
|
# File 'lib/apipie_dsl/dsl.rb', line 169
def method(name, desc = nil, _options = {})
dsl_data[:name] = name
dsl_data[:short_description] = desc
end
|
#raises(error_or_options, desc = nil, options = {}) ⇒ Object
Describe possible errors
Example:
raises :desc => "wrong argument", :error => ArgumentError, :meta => [:some, :more, :data]
raises ArgumentError, "wrong argument"
def print_string(string)
raise ArgumentError unless string.is_a?(String)
puts string
end
192
193
194
|
# File 'lib/apipie_dsl/dsl.rb', line 192
def raises(error_or_options, desc = nil, options = {})
dsl_data[:raises] << [error_or_options, desc, options]
end
|
#returns(retobj_or_options, desc_or_options = nil, options = {}, &block) ⇒ Object
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
|
# File 'lib/apipie_dsl/dsl.rb', line 196
def returns(retobj_or_options, desc_or_options = nil, options = {}, &block)
raise MultipleReturnsError unless dsl_data[:returns].nil?
if desc_or_options.is_a?(Hash)
options.merge!(desc_or_options)
elsif !desc_or_options.nil?
options[:desc] = desc_or_options
end
case retobj_or_options
when Hash
options.merge!(retobj_or_options)
when Symbol
options[:param_group] = retobj_or_options
else
options[:object_of] ||= retobj_or_options
end
options[:scope] ||= default_param_group_scope
raise ArgumentError, 'Block can be specified for Hash return type only' if block && (options[:object_of] != Hash)
data = [options, block]
dsl_data[:returns] = data unless options[:property]
data
end
|
#see(method, options = {}) ⇒ Object
Reference other similar method
method :print
see "MyIO#puts"
def print; end
228
229
230
231
|
# File 'lib/apipie_dsl/dsl.rb', line 228
def see(method, options = {})
args = [method, options]
dsl_data[:see] << args
end
|
#signature(*signature) ⇒ Object
178
179
180
|
# File 'lib/apipie_dsl/dsl.rb', line 178
def signature(*signature)
dsl_data[:signature] = signature
end
|