Class: Apes::Validators::BaseValidator

Inherits:
ActiveModel::EachValidator
  • Object
show all
Defined in:
lib/apes/validators.rb

Overview

The base validator.

Direct Known Subclasses

BooleanValidator, EmailValidator, PhoneValidator, ReferenceValidator, TimestampValidator, UuidValidator, ZipCodeValidator

Instance Method Summary (collapse)

Instance Method Details

- (Object) validate_each(model, attribute, value)

Perform validation on a attribute of a model.

Parameters:

  • model (Object)

    The object to validate.

  • attribute (String|Symbol)

    The attribute to validate.

  • value (Object)

    The value of the attribute.



16
17
18
19
20
21
22
23
24
# File 'lib/apes/validators.rb', line 16

def validate_each(model, attribute, value)
  checked = check_valid?(value)
  return checked if checked

  message = options[:message] || options[:default_message]
  destination = options[:additional] ? model.additional_errors : model.errors
  destination[attribute] << message
  nil
end