module ApipieDSL::Parameter

Constants

SUPPORTED_TYPES

Public Instance Methods

block(desc_or_options = nil, options = {}, &block) click to toggle source
# File lib/apipie_dsl/dsl.rb, line 119
def block(desc_or_options = nil, options = {}, &block)
  options[:type] = :block
  name = options[:name] || :block
  param(name, Proc, desc_or_options, options)
end
default_param_group_scope() click to toggle source

Where the group definition should be looked up when no scope given. This is expected to return a class.

# File lib/apipie_dsl/dsl.rb, line 161
def default_param_group_scope
  class_scope
end
define_param_group(name, &block) click to toggle source
# File lib/apipie_dsl/dsl.rb, line 133
def define_param_group(name, &block)
  ApipieDSL.define_param_group(class_scope, name, &block)
end
keyword(name, validator, desc_or_options = nil, options = {}, &block) click to toggle source
# File lib/apipie_dsl/dsl.rb, line 114
def keyword(name, validator, desc_or_options = nil, options = {}, &block)
  options[:type] = :keyword
  param(name, validator, desc_or_options, options, &block)
end
list(name, desc_or_options = nil, options = {}) click to toggle source
# File lib/apipie_dsl/dsl.rb, line 125
def list(name, desc_or_options = nil, options = {})
  options[:type] = :optional
  options[:default] ||= 'empty list'
  param(name, :rest, desc_or_options, options)
end
Also aliased as: splat, rest
optional(name, validator, desc_or_options = nil, options = {}, &block) click to toggle source
# File lib/apipie_dsl/dsl.rb, line 109
def optional(name, validator, desc_or_options = nil, options = {}, &block)
  options[:type] = :optional
  param(name, validator, desc_or_options, options, &block)
end
param(name, validator, desc_or_options = nil, options = {}, &block) click to toggle source

Describe method's parameter

Example:

param :greeting, String, :desc => "arbitrary text", :type => :required
def hello_world(greeting)
  puts greeting
end
# File lib/apipie_dsl/dsl.rb, line 96
def param(name, validator, desc_or_options = nil, options = {}, &block)
  dsl_data[:params] << [name,
                        validator,
                        desc_or_options,
                        options.merge(param_group: @current_param_group),
                        block]
end
param_group(name, scope_or_options = nil, options = {}) click to toggle source

Reuses param group for this method. The definition is looked up in scope of this class. If the group was defined in different class, the second param can be used to specify it.

# File lib/apipie_dsl/dsl.rb, line 140
def param_group(name, scope_or_options = nil, options = {})
  if scope_or_options.is_a?(Hash)
    options.merge!(scope_or_options)
    scope = options[:scope]
  else
    scope = scope_or_options
  end
  scope ||= default_param_group_scope

  @current_param_group = {
    scope: scope,
    name: name,
    options: options
  }
  instance_exec(&ApipieDSL.get_param_group(scope, name))
ensure
  @current_param_group = nil
end
required(name, validator, desc_or_options = nil, options = {}, &block) click to toggle source
# File lib/apipie_dsl/dsl.rb, line 104
def required(name, validator, desc_or_options = nil, options = {}, &block)
  options[:type] = :required
  param(name, validator, desc_or_options, options, &block)
end
rest(name, desc_or_options = nil, options = {})
Alias for: list
splat(name, desc_or_options = nil, options = {})
Alias for: list