Class: CouchRest::Validation::RequiredFieldValidator
- Inherits:
-
GenericValidator
- Object
- GenericValidator
- CouchRest::Validation::RequiredFieldValidator
- Defined in:
- lib/couchrest/validation/validators/required_field_validator.rb
Overview
Instance Attribute Summary
Attributes inherited from GenericValidator
#field_name, #if_clause, #unless_clause
Instance Method Summary collapse
- #call(target) ⇒ Object
-
#initialize(field_name, options = {}) ⇒ RequiredFieldValidator
constructor
A new instance of RequiredFieldValidator.
Methods inherited from GenericValidator
Constructor Details
#initialize(field_name, options = {}) ⇒ RequiredFieldValidator
Returns a new instance of RequiredFieldValidator.
33 34 35 36 |
# File 'lib/couchrest/validation/validators/required_field_validator.rb', line 33 def initialize(field_name, ={}) super @field_name, @options = field_name, end |
Instance Method Details
#call(target) ⇒ Object
38 39 40 41 42 43 44 45 46 47 |
# File 'lib/couchrest/validation/validators/required_field_validator.rb', line 38 def call(target) value = target.validation_property_value(field_name) property = target.validation_property(field_name) return true if present?(value, property) = @options[:message] || default_error(property) add_error(target, , field_name) false end |