Class: Waw::Validation::ArrayValidations::ArrayValidator

Inherits:
Validator show all
Defined in:
lib/waw/validation/array_validations.rb

Instance Method Summary collapse

Methods inherited from Validator

#&, #===, #=~, #not, #|

Methods included from Helpers

#all_missing?, #any_missing?, #argument_safe, #error, #is_missing?, #missings_to_nil, #no_missing?, #to_validator

Constructor Details

#initialize(subvalidator) ⇒ ArrayValidator

Creates a validator instance with a delegator



7
8
9
# File 'lib/waw/validation/array_validations.rb', line 7

def initialize(subvalidator)
  @subvalidator = Waw::Validation.to_validator(subvalidator)
end

Instance Method Details

#convert_and_validate(*values) ⇒ Object

Convert and validate method



17
18
19
20
21
22
23
24
25
26
# File 'lib/waw/validation/array_validations.rb', line 17

def convert_and_validate(*values)
  my_converted = []
  values.each do |val|
    return [false, values] unless ::Array===val
    ok, converted = @subvalidator.convert_and_validate(*val)
    return [false, values] unless ok
    my_converted << converted.compact
  end
  [true, my_converted]
end

#validate(*values) ⇒ Object

Validation method



12
13
14
# File 'lib/waw/validation/array_validations.rb', line 12

def validate(*values)
  values.all?{|val| val.is_a?(::Array) and @subvalidator.validate(*val) }
end