Class: DataValidator::AcceptanceValidator

Inherits:
BaseValidator show all
Defined in:
lib/validations/acceptance.rb

Instance Attribute Summary

Attributes inherited from BaseValidator

#errors, #name, #options, #value

Instance Method Summary collapse

Methods inherited from BaseValidator

#add_error, #check_validity!

Constructor Details

#initialize(name, value, options, errors) ⇒ AcceptanceValidator

Returns a new instance of AcceptanceValidator.

Raises:

  • (ArgumentError)


5
6
7
8
9
10
11
12
13
14
# File 'lib/validations/acceptance.rb', line 5

def initialize(name, value, options, errors)
  raise ArgumentError, 'Options must define' unless options
  case options
  when Hash
    options_base = options
  else
    options_base = {}
  end
  super(name, value, options_base.reverse_merge(:allow_nil => true, :accept => "1"), errors)
end

Instance Method Details

#validateObject



16
17
18
19
20
# File 'lib/validations/acceptance.rb', line 16

def validate
  unless value == options[:accept]
    add_error :accepted
  end
end