Class: DataMapper::Validations::AcceptanceValidator
- Inherits:
-
GenericValidator
- Object
- GenericValidator
- DataMapper::Validations::AcceptanceValidator
- Defined in:
- lib/dm-validations/validators/acceptance_validator.rb
Overview
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 = {}) ⇒ AcceptanceValidator
constructor
A new instance of AcceptanceValidator.
Methods inherited from GenericValidator
#==, #add_error, #evaluate_conditional_clause, #execute?, #inspect, #optional?, #set_optional_by_default
Constructor Details
#initialize(field_name, options = {}) ⇒ AcceptanceValidator
Returns a new instance of AcceptanceValidator.
7 8 9 10 11 12 13 14 |
# File 'lib/dm-validations/validators/acceptance_validator.rb', line 7 def initialize(field_name, = {}) super @options[:allow_nil] = true unless @options.key?(:allow_nil) @options[:accept] ||= [ '1', 1, 'true', true, 't' ] @options[:accept] = Array(@options[:accept]) end |
Instance Method Details
#call(target) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/dm-validations/validators/acceptance_validator.rb', line 16 def call(target) return true if valid?(target) = ( @options[:message] || ValidationErrors.( :accepted, field_name ) ) add_error(target, , field_name) false end |