Class: Apipie::Validator::NestedValidator
Instance Attribute Summary
#param_description
Class Method Summary
collapse
Instance Method Summary
collapse
#error, #expected_type, find, inherited, #merge_with, #param_name, #to_json, #to_s, #valid?
Constructor Details
#initialize(param_description, argument, param_group) ⇒ NestedValidator
Returns a new instance of NestedValidator.
347
348
349
350
351
|
# File 'lib/apipie/validator.rb', line 347
def initialize(param_description, argument, param_group)
super(param_description)
@validator = Apipie::Validator:: HashValidator.new(param_description, argument, param_group)
@type = argument
end
|
Class Method Details
.build(param_description, argument, options, block) ⇒ Object
371
372
373
374
375
|
# File 'lib/apipie/validator.rb', line 371
def self.build(param_description, argument, options, block)
self.new(param_description, block, options[:param_group]) if block.is_a?(Proc) && block.arity <= 0 && argument == Array
end
|
Instance Method Details
#description ⇒ Object
377
378
379
|
# File 'lib/apipie/validator.rb', line 377
def description
"Must be an Array of nested elements"
end
|
#params_ordered ⇒ Object
381
382
383
|
# File 'lib/apipie/validator.rb', line 381
def params_ordered
@validator.params_ordered
end
|
#process_value(value) ⇒ Object
362
363
364
365
366
367
368
369
|
# File 'lib/apipie/validator.rb', line 362
def process_value(value)
value ||= [] @values = []
value.each do |child|
@values << @validator.process_value(child)
end
@values
end
|
#validate(value) ⇒ Object
353
354
355
356
357
358
359
360
|
# File 'lib/apipie/validator.rb', line 353
def validate(value)
value ||= [] return false if value.class != Array
value.each do |child|
return false unless @validator.validate(child)
end
true
end
|