Class: WSDSL::Params
- Inherits:
-
Object
- Object
- WSDSL::Params
- Defined in:
- lib/params.rb
Overview
Service params class letting you define param rules. Usually not initialized directly but accessed via the service methods.
Defined Under Namespace
Classes: Rule
Instance Attribute Summary collapse
-
#space_name ⇒ String
readonly
The namespace used if any.
Params defintition DSL (accept_param style) collapse
-
#array(name, options = {}) ⇒ Array<WSDSL::Params::Rule>
Defines a new array param and add it to the required or optional list.
-
#binary(name, options = {}) ⇒ Arrays<WSDSL::Params::Rule>
Defines a new binary param and add it to the required or optional list.
-
#boolean(name, options = {}) ⇒ Arrays<WSDSL::Params::Rule>
Defines a new boolean param and add it to the required or optional list.
-
#datetime(name, options = {}) ⇒ Arrays<WSDSL::Params::Rule>
Defines a new datetime param and add it to the required or optional list.
-
#decimal(name, options = {}) ⇒ Arrays<WSDSL::Params::Rule>
Defines a new decimal param and add it to the required or optional list.
-
#file(name, options = {}) ⇒ Arrays<WSDSL::Params::Rule>
Defines a new file param and add it to the required or optional list.
-
#float(name, options = {}) ⇒ Arrays<WSDSL::Params::Rule>
Defines a new float param and add it to the required or optional list.
-
#integer(name, options = {}) ⇒ Arrays<WSDSL::Params::Rule>
Defines a new integer param and add it to the required or optional list.
-
#string(name, options = {}) ⇒ Arrays<WSDSL::Params::Rule>
Defines a new string param and add it to the required or optional list.
-
#text(name, options = {}) ⇒ Arrays<WSDSL::Params::Rule>
Defines a new text param and add it to the required or optional list.
param setters based on the state (required or optional) collapse
-
#optional(param_name, opts = {}) ⇒ Array<WSDSL::Params::Rule>
Defines a new optional param rule.
-
#required(param_name, opts = {}) ⇒ Array<WSDSL::Params::Rule>
Defines a new required param.
params accessors per status (required or optional) collapse
-
#list_optional ⇒ Array<WSDSL::Params::Rule>
Returns an array of all the optional params.
-
#list_required ⇒ Array<WSDSL::Params::Rule>
Returns an array of all the required params.
Instance Method Summary collapse
-
#initialize(opts = {}) ⇒ Params
constructor
A new instance of Params.
-
#namespace(name) {|Params| ... } ⇒ Array<WSDSL::Params>
Defines a namespaced param.
-
#namespaced_params ⇒ Array<WSDSL::Params>
Returns the namespaced params.
-
#param(type, name, options = {}) ⇒ Array
Defines a new param and add it to the optional or required list based the passed options.
-
#param_names ⇒ Array<WSDSL::Params>
Returns the names of the first level expected params.
Constructor Details
#initialize(opts = {}) ⇒ Params
Returns a new instance of Params.
71 72 73 |
# File 'lib/params.rb', line 71 def initialize(opts={}) @space_name = opts[:space_name] end |
Instance Attribute Details
#space_name ⇒ String (readonly)
The namespace used if any
66 67 68 |
# File 'lib/params.rb', line 66 def space_name @space_name end |
Instance Method Details
#array(name, options = {}) ⇒ Array<WSDSL::Params::Rule>
Defines a new array param and add it to the required or optional list
252 253 254 |
# File 'lib/params.rb', line 252 def array(name, ={}) param(:array, name, ) end |
#binary(name, options = {}) ⇒ Arrays<WSDSL::Params::Rule>
Defines a new binary param and add it to the required or optional list
235 236 237 |
# File 'lib/params.rb', line 235 def binary(name, ={}) param(:binary, name, ) end |
#boolean(name, options = {}) ⇒ Arrays<WSDSL::Params::Rule>
Defines a new boolean param and add it to the required or optional list
184 185 186 |
# File 'lib/params.rb', line 184 def boolean(name, ={}) param(:boolean, name, ) end |
#datetime(name, options = {}) ⇒ Arrays<WSDSL::Params::Rule>
Defines a new datetime param and add it to the required or optional list
201 202 203 |
# File 'lib/params.rb', line 201 def datetime(name, ={}) param(:datetime, name, ) end |
#decimal(name, options = {}) ⇒ Arrays<WSDSL::Params::Rule>
Defines a new decimal param and add it to the required or optional list
167 168 169 |
# File 'lib/params.rb', line 167 def decimal(name, ={}) param(:decimal, name, ) end |
#file(name, options = {}) ⇒ Arrays<WSDSL::Params::Rule>
Defines a new file param and add it to the required or optional list
269 270 271 |
# File 'lib/params.rb', line 269 def file(name, ={}) param(:file, name, ) end |
#float(name, options = {}) ⇒ Arrays<WSDSL::Params::Rule>
Defines a new float param and add it to the required or optional list
150 151 152 |
# File 'lib/params.rb', line 150 def float(name, ={}) param(:float, name, ) end |
#integer(name, options = {}) ⇒ Arrays<WSDSL::Params::Rule>
Defines a new integer param and add it to the required or optional list
133 134 135 |
# File 'lib/params.rb', line 133 def integer(name, ={}) param(:integer, name, ) end |
#list_optional ⇒ Array<WSDSL::Params::Rule>
Returns an array of all the optional params
338 339 340 |
# File 'lib/params.rb', line 338 def list_optional @optional ||= [] end |
#list_required ⇒ Array<WSDSL::Params::Rule>
Returns an array of all the required params
330 331 332 |
# File 'lib/params.rb', line 330 def list_required @required ||= [] end |
#namespace(name) {|Params| ... } ⇒ Array<WSDSL::Params>
Defines a namespaced param
349 350 351 352 353 |
# File 'lib/params.rb', line 349 def namespace(name) params = Params.new(:space_name => name) yield(params) if block_given? namespaced_params << params unless namespaced_params.include?(params) end |
#namespaced_params ⇒ Array<WSDSL::Params>
Returns the namespaced params
359 360 361 |
# File 'lib/params.rb', line 359 def namespaced_params @namespaced_params ||= [] end |
#optional(param_name, opts = {}) ⇒ Array<WSDSL::Params::Rule>
Defines a new optional param rule
315 316 317 318 319 320 321 322 |
# File 'lib/params.rb', line 315 def optional(param_name, opts={}) # # recursive rule creation # if opts.size > 1 # opts.each_pair{|k,v| optional({k => v})} # else list_optional << Rule.new(param_name, opts) # end end |
#param(type, name, options = {}) ⇒ Array
Defines a new param and add it to the optional or required list based the passed options.
91 92 93 94 95 96 97 98 99 |
# File 'lib/params.rb', line 91 def param(type, name, ={}) [:type] = type [:space_name] = [:space_name] || space_name if .delete(:required) list_required << Rule.new(name, ) else list_optional << Rule.new(name, ) end end |
#param_names ⇒ Array<WSDSL::Params>
Returns the names of the first level expected params
367 368 369 370 371 |
# File 'lib/params.rb', line 367 def param_names first_level_expected_params = (list_required + list_optional).map{|rule| rule.name.to_s} first_level_expected_params += namespaced_params.map{|r| r.space_name.to_s} first_level_expected_params end |
#required(param_name, opts = {}) ⇒ Array<WSDSL::Params::Rule>
Defines a new required param
289 290 291 292 293 294 295 296 297 298 299 300 |
# File 'lib/params.rb', line 289 def required(param_name, opts={}) # # support for when a required param doesn't have any options # unless opts.respond_to?(:each_pair) # opts = {opts => nil} # end # # recursive rule creation # if opts.size > 1 # opts.each_pair{|k,v| requires({k => v})} # else list_required << Rule.new(param_name, opts) # end end |
#string(name, options = {}) ⇒ Arrays<WSDSL::Params::Rule>
Defines a new string param and add it to the required or optional list
116 117 118 |
# File 'lib/params.rb', line 116 def string(name, ={}) param(:string, name, ) end |
#text(name, options = {}) ⇒ Arrays<WSDSL::Params::Rule>
Defines a new text param and add it to the required or optional list
218 219 220 |
# File 'lib/params.rb', line 218 def text(name, ={}) param(:text, name, ) end |