Module: ApipieDSL::Method

Includes:
Parameter
Included in:
Delegatable::Delegatee
Defined in:
lib/apipie_dsl/dsl.rb

Constant Summary

Constants included from Parameter

Parameter::SUPPORTED_TYPES

Instance Method Summary collapse

Methods included from Parameter

#block, #default_param_group_scope, #define_param_group, #keyword, #kwlist, #list, #optional, #param, #param_group, #required

Instance Method Details

#aliases(*names) ⇒ Object



182
183
184
# File 'lib/apipie_dsl/dsl.rb', line 182

def aliases(*names)
  dsl_data[:aliases] = names
end

#example(example, desc_or_options = nil, options = {}) ⇒ Object



241
242
243
244
245
246
247
248
# File 'lib/apipie_dsl/dsl.rb', line 241

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



250
251
252
253
254
255
256
257
# File 'lib/apipie_dsl/dsl.rb', line 250

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



177
178
179
180
# File 'lib/apipie_dsl/dsl.rb', line 177

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


200
201
202
# File 'lib/apipie_dsl/dsl.rb', line 200

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



204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
# File 'lib/apipie_dsl/dsl.rb', line 204

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


236
237
238
239
# File 'lib/apipie_dsl/dsl.rb', line 236

def see(method, options = {})
  args = [method, options]
  dsl_data[:see] << args
end

#signature(*signature) ⇒ Object



186
187
188
# File 'lib/apipie_dsl/dsl.rb', line 186

def signature(*signature)
  dsl_data[:signature] = signature
end