Class: Validatable::ValidatesConfirmationOf
- Inherits:
-
ValidationBase
- Object
- ValidationBase
- Validatable::ValidatesConfirmationOf
- Defined in:
- lib/validatable/validations/validates_confirmation_of.rb
Overview
:nodoc:
Instance Attribute Summary collapse
-
#case_sensitive ⇒ Object
Returns the value of attribute case_sensitive.
Attributes inherited from ValidationBase
#after_validate, #allow_blank, #allow_nil, #attribute, #if, #klass
Instance Method Summary collapse
-
#initialize(klass, attribute, options = {}) ⇒ ValidatesConfirmationOf
constructor
A new instance of ValidatesConfirmationOf.
- #message(instance) ⇒ Object
- #valid?(instance) ⇒ Boolean
Methods inherited from ValidationBase
Constructor Details
#initialize(klass, attribute, options = {}) ⇒ ValidatesConfirmationOf
Returns a new instance of ValidatesConfirmationOf.
5 6 7 8 9 10 11 12 13 |
# File 'lib/validatable/validations/validates_confirmation_of.rb', line 5 def initialize(klass, attribute, ={}) klass.class_eval do attr_accessor "_#{attribute}_confirmation" alias_method "#{attribute}_confirmation", "_#{attribute}_confirmation" alias_method "#{attribute}_confirmation=", "_#{attribute}_confirmation=" end super self.case_sensitive = true if self.case_sensitive == nil end |
Instance Attribute Details
#case_sensitive ⇒ Object
Returns the value of attribute case_sensitive.
3 4 5 |
# File 'lib/validatable/validations/validates_confirmation_of.rb', line 3 def case_sensitive @case_sensitive end |
Instance Method Details
#message(instance) ⇒ Object
23 24 25 |
# File 'lib/validatable/validations/validates_confirmation_of.rb', line 23 def (instance) super || "doesn't match confirmation" end |
#valid?(instance) ⇒ Boolean
15 16 17 18 19 20 21 |
# File 'lib/validatable/validations/validates_confirmation_of.rb', line 15 def valid?(instance) confirmation_value = instance.send("#{self.attribute}_confirmation") return true if allow_nil && confirmation_value.nil? return true if allow_blank && (!confirmation_value or (confirmation_value.respond_to?(:empty?) and confirmation_value.empty?)) return instance.send(self.attribute) == instance.send("#{self.attribute}_confirmation".to_sym) if case_sensitive instance.send(self.attribute).to_s.casecmp(instance.send("#{self.attribute}_confirmation".to_sym).to_s) == 0 end |