module Devise::Models::Validatable

def self.assert_validations_api!(base) #:nodoc:

:nodoc:
def self.assert_validations_api!(base) #:nodoc:
  unavailable_validations = VALIDATIONS.select { |v| !base.respond_to?(v) }
  unless unavailable_validations.empty?
    raise "Could not use :validatable module since #{base} does not respond " <<
          "to the following methods: #{unavailable_validations.to_sentence}."
  end
end

def self.included(base)

def self.included(base)
  assert_validations_api!(base)
  base.class_eval do
    validates_presence_of   :email
    validates_uniqueness_of :email, :scope => authentication_keys[1..-1], :allow_blank => true
    validates_format_of     :email, :with  => EMAIL_REGEX, :allow_blank => true
    with_options :if => :password_required? do |v|
      v.validates_presence_of     :password
      v.validates_confirmation_of :password
      v.validates_length_of       :password, :within => 6..20, :allow_blank => true
    end
  end
end