Class: EqualToValidator

Inherits:
ActiveModel::EachValidator
  • Object
show all
Defined in:
lib/casey_jones/validation/equal_to_validator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ EqualToValidator

Returns a new instance of EqualToValidator.



3
4
5
6
# File 'lib/casey_jones/validation/equal_to_validator.rb', line 3

def initialize(options)
  self.other = options[:other]
  super(options)
end

Instance Attribute Details

#otherObject

Returns the value of attribute other.



2
3
4
# File 'lib/casey_jones/validation/equal_to_validator.rb', line 2

def other
  @other
end

Instance Method Details

#validate_each(record, attribute, value) ⇒ Object



8
9
10
11
12
13
14
15
16
17
# File 'lib/casey_jones/validation/equal_to_validator.rb', line 8

def validate_each(record,attribute,value)
  if self.other==:password
    puts "checking password.  I was given #{value}.  User's @pw=#{record.instance_variable_get("@password")}"
    r = (value==record.instance_variable_get("@password"))
  else
    puts "checking #{attribute} not password.  I was given #{value}.  User's other=#{record.attributes[self.other]}"
    r = (value == record.attributes[self.other])
  end
  record.errors[attribute] << (options[:message] || "must be equal to #{self.other}") unless r
end