Class: Waw::Validation::IsInValidator

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

Overview

Checks that arguments belongs to an array of allowed values provided at construction time.

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(*allowed) ⇒ IsInValidator

Creates the validator instance



8
9
10
# File 'lib/waw/validation/isin_validator.rb', line 8

def initialize(*allowed)
  @allowed = (allowed.size==1 and Range===allowed[0]) ? allowed[0] : allowed
end

Instance Method Details

#convert_and_validate(*values) ⇒ Object

Convert and validate method



18
19
20
# File 'lib/waw/validation/isin_validator.rb', line 18

def convert_and_validate(*values)
  [validate(*values), values]
end

#validate(*values) ⇒ Object

Validation method



13
14
15
# File 'lib/waw/validation/isin_validator.rb', line 13

def validate(*values)
  values.all?{|v| @allowed.include?(v)}
end