module Devise::Models::Validatable
def self.assert_validations_api!(base) #: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) base.extend ClassMethods assert_validations_api!(base) base.class_eval do validates_presence_of :email, :if => :email_required? validates_uniqueness_of :email, :allow_blank => true, :if => :email_changed? validates_format_of :email, :with => email_regexp, :allow_blank => true, :if => :email_changed? validates_presence_of :password, :if => :password_required? validates_confirmation_of :password, :if => :password_required? validates_length_of :password, :within => password_length, :allow_blank => true end end
def self.required_fields(klass)
def self.required_fields(klass) [] end
def email_required?
def email_required? true end
def password_required?
Passwords are always required if it's a new record, or if the password
Checks whether a password is needed or not. For validations only.
def password_required? !persisted? || !password.nil? || !password_confirmation.nil? end