From 386e7be82326be67ad8a860b6dc4b4ec8bd0c30a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Fri, 26 Mar 2010 12:19:01 +0100 Subject: [PATCH] Move password_required? to authenticatable. This allow you to reuse it when building your own validations. --- lib/devise/models/authenticatable.rb | 7 +++++++ lib/devise/models/validatable.rb | 9 --------- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/lib/devise/models/authenticatable.rb b/lib/devise/models/authenticatable.rb index 2f295209..9755a387 100644 --- a/lib/devise/models/authenticatable.rb +++ b/lib/devise/models/authenticatable.rb @@ -94,6 +94,13 @@ module Devise protected + # Checks whether a password is needed or not. For validations only. + # Passwords are always required if it's a new record, or if the password + # or confirmation are being set somewhere. + def password_required? + new_record? || !password.nil? || !password_confirmation.nil? + end + # Digests the password using the configured encryptor. def password_digest(password) self.class.encryptor_class.digest(password, self.class.stretches, self.password_salt, self.class.pepper) diff --git a/lib/devise/models/validatable.rb b/lib/devise/models/validatable.rb index a31276c6..737ec9a2 100644 --- a/lib/devise/models/validatable.rb +++ b/lib/devise/models/validatable.rb @@ -34,15 +34,6 @@ module Devise "to the following methods: #{unavailable_validations.to_sentence}." end end - - protected - - # Checks whether a password is needed or not. For validations only. - # Passwords are always required if it's a new record, or if the password - # or confirmation are being set somewhere. - def password_required? - new_record? || !password.nil? || !password_confirmation.nil? - end end end end