Class: DataMapper::Validations::GenericValidator
- Defined in:
- lib/data_mapper/validations/generic_validator.rb
Overview
All Validators should inherit from the GenericValidator.
Direct Known Subclasses
ConfirmationValidator, FormatValidator, LengthValidator, RequiredFieldValidator, UniqueValidator
Instance Method Summary collapse
-
#add_error(target, message, attribute = :base) ⇒ Object
Adds an error message to the target class.
-
#call(target) ⇒ Object
Call the validator.
-
#validation_error_message(default, custom_message, validation_binding) ⇒ Object
Gets the proper error message.
Instance Method Details
#add_error(target, message, attribute = :base) ⇒ Object
Adds an error message to the target class.
8 9 10 |
# File 'lib/data_mapper/validations/generic_validator.rb', line 8 def add_error(target, , attribute = :base) target.errors.add(attribute, ) end |
#call(target) ⇒ Object
Call the validator. We use “call” so the operation is BoundMethod and Block compatible. The result should always be TRUE or FALSE.
20 21 22 |
# File 'lib/data_mapper/validations/generic_validator.rb', line 20 def call(target) raise 'You must overwrite this method' end |
#validation_error_message(default, custom_message, validation_binding) ⇒ Object
Gets the proper error message
13 14 15 |
# File 'lib/data_mapper/validations/generic_validator.rb', line 13 def (default, , validation_binding) eval("\"#{( || default)}\"", validation_binding) end |