Sha256: 54929acd9a126eb26ca3f80de6bc7b3bc227abbeabc3dfa0f9a0802903298f83

Contents?: true

Size: 1.21 KB

Versions: 19

Compression:

Stored size: 1.21 KB

Contents

require 'whyvalidationssuckin96/skippable_validation'
require 'whyvalidationssuckin96/attribute_based_validation'

module WhyValidationsSuckIn96
  
  # Checks the validity of an attribute against a confirmation field. Note that this validation does
  # not set up the confirmation field on the object, leaving this up to the implementer.
  #
  # @example Default usage
  #   class Account
  #     attr_accessor :password, :password_confirmation
  #     setup_validations do
  #       validates_confirmation_of :password
  #     end
  #   end
  class ValidatesConfirmation < Validation  
    include WhyValidationsSuckIn96::SkippableValidation
    include WhyValidationsSuckIn96::AttributeBasedValidation
    
    DefaultOptions = {:message => "does not match the confirmation"}
    
    def validate
      super
      skip unless confirmation_value = validatable.send(confirmation_field)
      if confirmation_value == attribute_value
        pass
      else
        fail
      end
    end
    
  private
  
    def confirmation_field
      :"#{attribute}_confirmation"
    end
  end # Validation

  ValidationBuilder.register_macro :validates_confirmation_of, WhyValidationsSuckIn96::ValidatesAcceptance
end   # WhyValidationsSuckIn96

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
whyvalidationssuckin96-1.6.3 lib/whyvalidationssuckin96/macros/validates_confirmation.rb
whyvalidationssuckin96-1.6.2 lib/whyvalidationssuckin96/macros/validates_confirmation.rb
whyvalidationssuckin96-1.6.1 lib/whyvalidationssuckin96/macros/validates_confirmation.rb
whyvalidationssuckin96-1.6.0 lib/whyvalidationssuckin96/macros/validates_confirmation.rb
whyvalidationssuckin96-1.5.5 lib/whyvalidationssuckin96/macros/validates_confirmation.rb
whyvalidationssuckin96-1.5.4 lib/whyvalidationssuckin96/macros/validates_confirmation.rb
whyvalidationssuckin96-1.5.3 lib/whyvalidationssuckin96/macros/validates_confirmation.rb
whyvalidationssuckin96-1.5.2 lib/whyvalidationssuckin96/macros/validates_confirmation.rb
whyvalidationssuckin96-1.5.1 lib/whyvalidationssuckin96/macros/validates_confirmation.rb
whyvalidationssuckin96-1.5.0 lib/whyvalidationssuckin96/macros/validates_confirmation.rb
whyvalidationssuckin96-1.4.0 lib/whyvalidationssuckin96/macros/validates_confirmation.rb
whyvalidationssuckin96-1.3.1 lib/whyvalidationssuckin96/macros/validates_confirmation.rb
whyvalidationssuckin96-1.3.0 lib/whyvalidationssuckin96/macros/validates_confirmation.rb
whyvalidationssuckin96-1.2.3 lib/whyvalidationssuckin96/macros/validates_confirmation.rb
whyvalidationssuckin96-1.2.2 lib/whyvalidationssuckin96/macros/validates_confirmation.rb
whyvalidationssuckin96-1.2.1 lib/whyvalidationssuckin96/macros/validates_confirmation.rb
whyvalidationssuckin96-1.2.0 lib/whyvalidationssuckin96/macros/validates_confirmation.rb
whyvalidationssuckin96-1.1.0 lib/whyvalidationssuckin96/macros/validates_confirmation.rb
whyvalidationssuckin96-1.0.0 lib/whyvalidationssuckin96/macros/validates_confirmation.rb