Module: Apipie::DSL::Param
- Included in:
- Concern, Controller, ResourceDescriptionDsl, Validator::HashValidator
- Defined in:
- lib/apipie/dsl_definition.rb
Overview
this describes the params, it’s in separate module because it’s used in Validators as well
Instance Method Summary collapse
-
#_default_param_group_scope ⇒ Object
where the group definition should be looked up when no scope given.
-
#param(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.
Instance Method Details
#_default_param_group_scope ⇒ Object
where the group definition should be looked up when no scope given. This is expected to return a controller.
337 338 339 |
# File 'lib/apipie/dsl_definition.rb', line 337 def _default_param_group_scope self end |
#param(param_name, validator, desc_or_options = nil, options = {}, &block) ⇒ Object
Describe method’s parameter
Example:
param :greeting, String, :desc => "arbitrary text", :required => true
def hello_world(greeting)
puts greeting
end
301 302 303 304 305 306 307 308 |
# File 'lib/apipie/dsl_definition.rb', line 301 def param(param_name, validator, = nil, = {}, &block) #:doc: return unless Apipie.active_dsl? _apipie_dsl_data[:params] << [param_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 controller. If the group was defined in different controller, the second param can be used to specify it. when using action_aware parmas, you can specify :as => :create or :update to explicitly say how it should behave
315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 |
# File 'lib/apipie/dsl_definition.rb', line 315 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 => , :from_concern => scope.apipie_concern? } self.instance_exec(&Apipie.get_param_group(scope, name)) ensure @_current_param_group = nil end |