Class: Validatable::ValidatesConfirmationOf
- Inherits:
-
ValidationBase
- Object
- ValidationBase
- Validatable::ValidatesConfirmationOf
- Defined in:
- lib/validations/validates_confirmation_of.rb
Overview
:nodoc:
Instance Attribute Summary
Attributes inherited from ValidationBase
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
after_validate, after_validations, all_after_validations, all_defaults, default, defaults, option, #raise_error_if_key_is_dup, required_option, #run_after_validate, #should_validate?, #validate_this_time?
Methods included from Requireable
Methods included from Understandable
Constructor Details
#initialize(klass, attribute, options = {}) ⇒ ValidatesConfirmationOf
Returns a new instance of ValidatesConfirmationOf.
6 7 8 9 |
# File 'lib/validations/validates_confirmation_of.rb', line 6 def initialize(klass, attribute, ={}) klass.class_eval { attr_accessor "#{attribute}_confirmation" } super end |
Instance Method Details
#message(instance) ⇒ Object
19 20 21 |
# File 'lib/validations/validates_confirmation_of.rb', line 19 def (instance) super || "doesn't match confirmation" end |
#valid?(instance) ⇒ Boolean
11 12 13 14 15 16 17 |
# File 'lib/validations/validates_confirmation_of.rb', line 11 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.blank? 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 |