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

Version Path
hashrocket-validatable-1.7.2 lib/validations/validates_confirmation_of.rb
hashrocket-validatable-1.7.4 lib/validations/validates_confirmation_of.rb
jnunemaker-validatable-1.7.0 lib/validations/validates_confirmation_of.rb
jnunemaker-validatable-1.7.1 lib/validations/validates_confirmation_of.rb
jnunemaker-validatable-1.7.2 lib/validations/validates_confirmation_of.rb
vizjerai-validatable-1.8.0 lib/validations/validates_confirmation_of.rb
vizjerai-validatable-1.9.0 lib/validations/validates_confirmation_of.rb
lgustafson-validatable-1.8.7 lib/validatable/validations/validates_confirmation_of.rb
lgustafson-validatable-1.8.6 lib/validatable/validations/validates_confirmation_of.rb
np422-validatable-1.8.5 lib/validatable/validations/validates_confirmation_of.rb
erotte-validatable-1.8.5 lib/validatable/validations/validates_confirmation_of.rb
mattmatt-validatable-1.8.3 lib/validatable/validations/validates_confirmation_of.rb
jnunemaker-validatable-1.8.4 lib/validatable/validations/validates_confirmation_of.rb
jnunemaker-validatable-1.8.3 lib/validatable/validations/validates_confirmation_of.rb
jnunemaker-validatable-1.8.2 lib/validatable/validations/validates_confirmation_of.rb
jnunemaker-validatable-1.1.10 lib/validatable/validations/validates_confirmation_of.rb
jnunemaker-validatable-1.1.9 lib/validatable/validations/validates_confirmation_of.rb
durran-validatable-2.0.1 lib/validations/validates_confirmation_of.rb
durran-validatable-2.0.0 lib/validations/validates_confirmation_of.rb
durran-validatable-1.8.4 lib/validations/validates_confirmation_of.rb