Class: Apipie::Validator::NestedValidator
Instance Attribute Summary
#param_description
Class Method Summary
collapse
Instance Method Summary
collapse
#==, #error, find, #format_description_value, #ignore_allow_blank?, inherited, #inspect, #inspected_fields, #merge_with, #param_name, #params_ordered, raise_if_missing_params, #to_json, #to_s, #valid?
Constructor Details
#initialize(param_description, argument, param_group) ⇒ NestedValidator
Returns a new instance of NestedValidator.
510
511
512
513
514
|
# File 'lib/apipie/validator.rb', line 510
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
534
535
536
537
538
|
# File 'lib/apipie/validator.rb', line 534
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
544
545
546
|
# File 'lib/apipie/validator.rb', line 544
def description
"Must be an Array of nested elements"
end
|
#expected_type ⇒ Object
540
541
542
|
# File 'lib/apipie/validator.rb', line 540
def expected_type
'array'
end
|
#process_value(value) ⇒ Object
525
526
527
528
529
530
531
532
|
# File 'lib/apipie/validator.rb', line 525
def process_value(value)
value ||= []
@values = []
value.each do |child|
@values << @validator.process_value(child)
end
@values
end
|
#validate(value) ⇒ Object
516
517
518
519
520
521
522
523
|
# File 'lib/apipie/validator.rb', line 516
def validate(value)
value ||= []
return false if value.class != Array
value.each do |child|
return false unless @validator.validate(child)
end
true
end
|