class Apipie::Validator::NestedValidator
Public Class Methods
build(param_description, argument, options, block)
click to toggle source
# File lib/apipie/validator.rb, line 507 def self.build(param_description, argument, options, block) # in Ruby 1.8.x the arity on block without args is -1 # while in Ruby 1.9+ it is 0 self.new(param_description, block, options[:param_group]) if block.is_a?(Proc) && block.arity <= 0 && argument == Array end
new(param_description, argument, param_group)
click to toggle source
Calls superclass method
Apipie::Validator::BaseValidator::new
# File lib/apipie/validator.rb, line 483 def initialize(param_description, argument, param_group) super(param_description) @validator = Apipie::Validator:: HashValidator.new(param_description, argument, param_group) @type = argument end
Public Instance Methods
description()
click to toggle source
# File lib/apipie/validator.rb, line 517 def description "Must be an Array of nested elements" end
expected_type()
click to toggle source
# File lib/apipie/validator.rb, line 513 def expected_type 'array' end
params_ordered()
click to toggle source
# File lib/apipie/validator.rb, line 521 def params_ordered @validator.params_ordered end
process_value(value)
click to toggle source
# File lib/apipie/validator.rb, line 498 def process_value(value) value ||= [] # Rails convert empty array to nil @values = [] value.each do |child| @values << @validator.process_value(child) end @values end
validate(value)
click to toggle source
# File lib/apipie/validator.rb, line 489 def validate(value) value ||= [] # Rails convert empty array to nil return false if value.class != Array value.each do |child| return false unless @validator.validate(child) end true end