Sha256: e058123809967d27c4d492b575f168eaf028c39f08c9d8b7100df3af954b7613
Contents?: true
Size: 842 Bytes
Versions: 29
Compression:
Stored size: 842 Bytes
Contents
module Validatable class ValidatesConfirmationOf < ValidationBase #:nodoc: option :case_sensitive default :case_sensitive => true def initialize(klass, attribute, options={}) klass.class_eval { attr_accessor "#{attribute}_confirmation" } super end 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 def message(instance) super || "doesn't match confirmation" end end end
Version data entries
29 entries across 29 versions & 8 rubygems