Class Index [+]

Quicksearch

DataMapper::Validations::AcceptanceValidator

@author Martin Kihlgren @since 0.9

Public Class Methods

new(field_name, options = {}) click to toggle source
    # File lib/dm-validations/validators/acceptance_validator.rb, line 7
 7:       def initialize(field_name, options = {})
 8:         super
 9: 
10:         @options[:allow_nil] = true unless @options.key?(:allow_nil)
11: 
12:         @options[:accept] ||= [ '1', 1, 'true', true, 't' ]
13:         @options[:accept] = Array(@options[:accept])
14:       end

Public Instance Methods

call(target) click to toggle source
    # File lib/dm-validations/validators/acceptance_validator.rb, line 16
16:       def call(target)
17:         return true if valid?(target)
18: 
19:         error_message = (
20:           @options[:message] || ValidationErrors.default_error_message(
21:             :accepted, field_name
22:           )
23:         )
24:         add_error(target, error_message, field_name)
25: 
26:         false
27:       end

Private Instance Methods

allow_nil?(value) click to toggle source
    # File lib/dm-validations/validators/acceptance_validator.rb, line 37
37:       def allow_nil?(value)
38:         @options[:allow_nil] && value.nil?
39:       end
valid?(target) click to toggle source
    # File lib/dm-validations/validators/acceptance_validator.rb, line 31
31:       def valid?(target)
32:         value = target.validation_property_value(field_name)
33:         return true if allow_nil?(value)
34:         @options[:accept].include?(value)
35:       end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.