Class: Apes::Validators::BaseValidator

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

Overview

The base validator.

Instance Method Summary collapse

Instance Method Details

#validate_each(model, attribute, value) ⇒ Object

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