Class: DataMapper::Validations::GenericValidator

Inherits:
Object
  • Object
show all
Defined in:
lib/data_mapper/validations/generic_validator.rb

Overview

All Validators should inherit from the GenericValidator.

Instance Method Summary collapse

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, message, attribute = :base)
  target.errors.add(attribute, message)
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 validation_error_message(default, custom_message, validation_binding)
  eval("\"#{(custom_message || default)}\"", validation_binding)
end