Class: Apipie::Validator::NestedValidator
Instance Attribute Summary
#param_description
Class Method Summary
collapse
Instance Method Summary
collapse
#==, #error, find, inherited, #inspect, #inspected_fields, #merge_with, #param_name, #to_json, #to_s, #valid?
Constructor Details
#initialize(param_description, argument, param_group) ⇒ NestedValidator
Returns a new instance of NestedValidator.
471
472
473
474
475
|
# File 'lib/apipie/validator.rb', line 471
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
495
496
497
498
499
|
# File 'lib/apipie/validator.rb', line 495
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
505
506
507
|
# File 'lib/apipie/validator.rb', line 505
def description
"Must be an Array of nested elements"
end
|
#expected_type ⇒ Object
501
502
503
|
# File 'lib/apipie/validator.rb', line 501
def expected_type
'array'
end
|
#params_ordered ⇒ Object
509
510
511
|
# File 'lib/apipie/validator.rb', line 509
def params_ordered
@validator.params_ordered
end
|
#process_value(value) ⇒ Object
486
487
488
489
490
491
492
493
|
# File 'lib/apipie/validator.rb', line 486
def process_value(value)
value ||= [] @values = []
value.each do |child|
@values << @validator.process_value(child)
end
@values
end
|
#validate(value) ⇒ Object
477
478
479
480
481
482
483
484
|
# File 'lib/apipie/validator.rb', line 477
def validate(value)
value ||= [] return false if value.class != Array
value.each do |child|
return false unless @validator.validate(child)
end
true
end
|