Class: DataMapper::Validate::AbsentFieldValidator
- Inherits:
-
GenericValidator
- Object
- GenericValidator
- DataMapper::Validate::AbsentFieldValidator
- Defined in:
- lib/gems/dm-validations-0.9.9/lib/dm-validations/absent_field_validator.rb
Overview
Instance Attribute Summary
Attributes inherited from GenericValidator
Instance Method Summary collapse
- #call(target) ⇒ Object
-
#initialize(field_name, options = {}) ⇒ AbsentFieldValidator
constructor
A new instance of AbsentFieldValidator.
Methods inherited from GenericValidator
#==, #add_error, #execute?, #field_name
Constructor Details
#initialize(field_name, options = {}) ⇒ AbsentFieldValidator
Returns a new instance of AbsentFieldValidator.
10 11 12 13 |
# File 'lib/gems/dm-validations-0.9.9/lib/dm-validations/absent_field_validator.rb', line 10 def initialize(field_name, ={}) super @field_name, @options = field_name, end |
Instance Method Details
#call(target) ⇒ Object
15 16 17 18 19 20 21 22 23 |
# File 'lib/gems/dm-validations-0.9.9/lib/dm-validations/absent_field_validator.rb', line 15 def call(target) field_value = target.send(field_name).blank? return true if field_value = @options[:message] || "%s must be absent".t(Extlib::Inflection.humanize(@field_name)) add_error(target, , @field_name) return false end |