Class | DataMapper::Validations::GenericValidator |
In: |
lib/dm-validations/validators/generic_validator.rb
|
Parent: | Object |
All validators extend this base class. Validators must:
@author Guy van den Berg @since 0.9
field_name | [R] | |
humanized_field_name | [R] | |
if_clause | [RW] | |
options | [R] | |
unless_clause | [RW] |
Construct a validator. Capture the :if and :unless clauses when present.
@param [String, Symbol] field
The property specified for validation.
@option [Symbol, Proc] :if
The name of a method or a Proc to call to determine if the validation should occur.
@option [Symbol, Proc] :unless
The name of a method or a Proc to call to determine if the validation should not occur.
@note
All additional key/value pairs are passed through to the validator that is sub-classing this GenericValidator
Returns true if validators are equal
Note that this intentionally do validate options equality
even though it is hard to imagine a situation when multiple validations will be used on the same field with the same conditions but different options, it happens to be the case every once in a while with inferred validations for strings/text and explicitly given validations with different option (usually as Range vs. max limit for inferred validation)
@api semipublic
Add an error message to a target resource. If the error corresponds to a specific field of the resource, add it to that field, otherwise add it as a :general message.
@param [Object] target
The resource that has the error.
@param [String] message
The message to add.
@param [Symbol] field_name
The name of the field that caused the error.
Determines if this validator should be run against the target by evaluating the :if and :unless clauses optionally passed while specifying any validator.
@param [Object] target
The resource that we check against.
@return [Boolean]
true if should be run, otherwise false.
@api private
Test the value to see if it is blank or nil, and if it is allowed. Note that allowing blank without explicitly denying nil allows nil values, since nil.blank? is true.
@param [Object] value
The value to test.
@return [Boolean]
true if blank/nil is allowed, and the value is blank/nil.
@api private