Class: VanillaValidator::Rules::Required
- Defined in:
- lib/vanilla_validator/rules/required.rb
Instance Attribute Summary
Attributes inherited from BaseRule
#attribute, #parameters, #value
Instance Method Summary collapse
Methods inherited from BaseRule
Constructor Details
This class inherits a constructor from VanillaValidator::Rules::BaseRule
Instance Method Details
#failure_message ⇒ Object
16 17 18 |
# File 'lib/vanilla_validator/rules/required.rb', line 16 def I18n.t('required', attribute: attribute) end |
#valid? ⇒ Boolean
4 5 6 7 8 9 10 11 12 13 14 |
# File 'lib/vanilla_validator/rules/required.rb', line 4 def valid? if value.nil? return false elsif value.class == String && value.strip == '' return false elsif value.class == Array && value.count < 1 return false end return true end |