Class: PureValidator::Validators::PresenceValidator
- Inherits:
-
Object
- Object
- PureValidator::Validators::PresenceValidator
- Defined in:
- lib/pure_validator/validators/presence_validator.rb
Class Method Summary collapse
-
.validate(value, presence) ⇒ Array
Validates that given object not nil and not empty if string is given strips it before validating.
- .validate_options(presence_flag) ⇒ Object
Class Method Details
.validate(value, presence) ⇒ Array
Validates that given object not nil and not empty if string is given strips it before validating
8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/pure_validator/validators/presence_validator.rb', line 8 def self.validate(value, presence) errors = [] if presence if value.nil? || (value.is_a?(String) && value.strip.length == 0) errors << PureValidator::I18n.t('errors.can_not_be_blank') end else if value errors << PureValidator::I18n.t('errors.should_be_blank') end end errors end |
.validate_options(presence_flag) ⇒ Object
22 23 24 |
# File 'lib/pure_validator/validators/presence_validator.rb', line 22 def self.(presence_flag) PureValidator::ArgsValidator.is_boolean!(presence_flag, :validation_rule) end |