Class: DataMapper::Validations::FormatValidator
- Inherits:
-
GenericValidator
- Object
- GenericValidator
- DataMapper::Validations::FormatValidator
- Defined in:
- lib/dm-validations/validators/format_validator.rb
Overview
Constant Summary collapse
- FORMATS =
{}
Constants included from DataMapper::Validations::Format::Url
DataMapper::Validations::Format::Url::Url
Constants included from DataMapper::Validations::Format::Email
DataMapper::Validations::Format::Email::EmailAddress
Instance Attribute Summary
Attributes inherited from GenericValidator
#field_name, #humanized_field_name, #if_clause, #options, #unless_clause
Instance Method Summary collapse
- #call(target) ⇒ Object
-
#initialize(field_name, options = {}) ⇒ FormatValidator
constructor
A new instance of FormatValidator.
Methods included from DataMapper::Validations::Format::Url
Methods included from DataMapper::Validations::Format::Email
Methods inherited from GenericValidator
#==, #add_error, #evaluate_conditional_clause, #execute?, #inspect, #optional?, #set_optional_by_default
Constructor Details
#initialize(field_name, options = {}) ⇒ FormatValidator
Returns a new instance of FormatValidator.
20 21 22 23 24 |
# File 'lib/dm-validations/validators/format_validator.rb', line 20 def initialize(field_name, = {}) super set_optional_by_default end |
Instance Method Details
#call(target) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/dm-validations/validators/format_validator.rb', line 26 def call(target) return true if valid?(target) value = target.validation_property_value(field_name) = ( @options[:message] || ValidationErrors.( :invalid, field_name ) ) add_error( target, .try_call(humanized_field_name, value), field_name ) false end |