Class: DataMapper::Validations::LengthValidator
- Inherits:
-
GenericValidator
- Object
- GenericValidator
- DataMapper::Validations::LengthValidator
- Defined in:
- lib/dm-validations/validators/length_validator.rb
Instance Attribute Summary
Attributes inherited from GenericValidator
#field_name, #humanized_field_name, #if_clause, #options, #unless_clause
Instance Method Summary collapse
-
#call(target) ⇒ Boolean
Test the resource field for validity.
-
#initialize(field_name, options) ⇒ LengthValidator
constructor
Initialize a length validator.
Methods inherited from GenericValidator
#==, #add_error, #evaluate_conditional_clause, #execute?, #inspect, #optional?, #set_optional_by_default
Constructor Details
#initialize(field_name, options) ⇒ LengthValidator
Initialize a length validator
14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/dm-validations/validators/length_validator.rb', line 14 def initialize(field_name, ) super @equal = [:is] || [:equals] @range = [:within] || [:in] @min = [:minimum] || [:min] @max = [:maximum] || [:max] if @min && @max @range ||= @min..@max end end |
Instance Method Details
#call(target) ⇒ Boolean
Test the resource field for validity
43 44 45 46 47 48 49 50 51 |
# File 'lib/dm-validations/validators/length_validator.rb', line 43 def call(target) value = target.validation_property_value(field_name) return true if optional?(value) return true unless = (value) add_error(target, , field_name) false end |