Module: ApipieDSL::Parameter
- Included in:
- Method, ReturnDescription::ReturnObject, Validator::HashValidator
- Defined in:
- lib/apipie_dsl/dsl.rb
Constant Summary collapse
- SUPPORTED_TYPES =
%i[required optional keyword block].freeze
Instance Method Summary collapse
- #block(desc_or_options = nil, options = {}, &block) ⇒ Object
-
#default_param_group_scope ⇒ Object
Where the group definition should be looked up when no scope given.
- #define_param_group(name, &block) ⇒ Object
- #keyword(name, validator, desc_or_options = nil, options = {}, &block) ⇒ Object
- #list(name, desc_or_options = nil, options = {}) ⇒ Object (also: #splat, #rest)
- #optional(name, validator, desc_or_options = nil, options = {}, &block) ⇒ Object
-
#param(name, validator, desc_or_options = nil, options = {}, &block) ⇒ Object
Describe method’s parameter.
-
#param_group(name, scope_or_options = nil, options = {}) ⇒ Object
Reuses param group for this method.
- #required(name, validator, desc_or_options = nil, options = {}, &block) ⇒ Object
Instance Method Details
#block(desc_or_options = nil, options = {}, &block) ⇒ Object
119 120 121 122 123 |
# File 'lib/apipie_dsl/dsl.rb', line 119 def block( = nil, = {}, &block) [:type] = :block name = [:name] || :block param(name, Proc, , ) end |
#default_param_group_scope ⇒ Object
Where the group definition should be looked up when no scope given. This is expected to return a class.
161 162 163 |
# File 'lib/apipie_dsl/dsl.rb', line 161 def default_param_group_scope class_scope end |
#define_param_group(name, &block) ⇒ Object
133 134 135 |
# 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) ⇒ Object
114 115 116 117 |
# File 'lib/apipie_dsl/dsl.rb', line 114 def keyword(name, validator, = nil, = {}, &block) [:type] = :keyword param(name, validator, , , &block) end |
#list(name, desc_or_options = nil, options = {}) ⇒ Object Also known as: splat, rest
125 126 127 128 129 |
# File 'lib/apipie_dsl/dsl.rb', line 125 def list(name, = nil, = {}) [:type] = :optional [:default] ||= 'empty list' param(name, :rest, , ) end |
#optional(name, validator, desc_or_options = nil, options = {}, &block) ⇒ Object
109 110 111 112 |
# File 'lib/apipie_dsl/dsl.rb', line 109 def optional(name, validator, = nil, = {}, &block) [:type] = :optional param(name, validator, , , &block) end |
#param(name, validator, desc_or_options = nil, options = {}, &block) ⇒ Object
Describe method’s parameter
Example:
param :greeting, String, :desc => "arbitrary text", :type => :required
def hello_world(greeting)
puts greeting
end
96 97 98 99 100 101 102 |
# File 'lib/apipie_dsl/dsl.rb', line 96 def param(name, validator, = nil, = {}, &block) dsl_data[:params] << [name, validator, , .merge(param_group: @current_param_group), block] end |
#param_group(name, scope_or_options = nil, options = {}) ⇒ Object
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.
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 |
# File 'lib/apipie_dsl/dsl.rb', line 140 def param_group(name, = nil, = {}) if .is_a?(Hash) .merge!() scope = [:scope] else scope = end scope ||= default_param_group_scope @current_param_group = { scope: scope, name: name, options: } instance_exec(&ApipieDSL.get_param_group(scope, name)) ensure @current_param_group = nil end |
#required(name, validator, desc_or_options = nil, options = {}, &block) ⇒ Object
104 105 106 107 |
# File 'lib/apipie_dsl/dsl.rb', line 104 def required(name, validator, = nil, = {}, &block) [:type] = :required param(name, validator, , , &block) end |