Class: EqualToValidator
- Inherits:
-
ActiveModel::EachValidator
- Object
- ActiveModel::EachValidator
- EqualToValidator
- Defined in:
- lib/casey_jones/validation/equal_to_validator.rb
Instance Attribute Summary collapse
-
#other ⇒ Object
Returns the value of attribute other.
Instance Method Summary collapse
-
#initialize(options) ⇒ EqualToValidator
constructor
A new instance of EqualToValidator.
- #validate_each(record, attribute, value) ⇒ Object
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() self.other = [:other] super() end |
Instance Attribute Details
#other ⇒ Object
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] << ([:message] || "must be equal to #{self.other}") unless r end |