Class: Waw::Validation::IsInValidator
- 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
-
#convert_and_validate(*values) ⇒ Object
Convert and validate method.
-
#initialize(*allowed) ⇒ IsInValidator
constructor
Creates the validator instance.
-
#validate(*values) ⇒ Object
Validation method.
Methods inherited from Validator
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 |