From 6ba42affc74f7f3b8eabe48a3615870815c5560e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Sun, 15 Nov 2009 20:35:19 -0200 Subject: [PATCH] Allow schema options to work together with devise method in ORMs where devise and schema are in the same class (as in Datamapper and MongoMapper). --- lib/devise/schema.rb | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/lib/devise/schema.rb b/lib/devise/schema.rb index dc8ab6a9..880b1240 100644 --- a/lib/devise/schema.rb +++ b/lib/devise/schema.rb @@ -6,13 +6,19 @@ module Devise # Creates email, encrypted_password and password_salt. # # == Options - # * :null when true, allow columns to be null - # * :encryptor The encryptor going to be used, necessary for setting the proper encrypter password length + # * :null - When true, allow columns to be null. + # * :encryptor - The encryptor going to be used, necessary for setting the proper encrypter password length. + # * :skip_email - If you want to use another authentication key, you can skip e-mail creation. + # If you are using an ORM where the devise declaration is in the same class as the schema, + # as in Datamapper or Mongomapper, the email is skipped automatically if not included in + # authentication_keys. def authenticatable(options={}) null = options[:null] || false - encryptor = options[:encryptor] || :sha1 + encryptor = options[:encryptor] || (respond_to?(:encryptor) ? self.encryptor : :sha1) + have_email = respond_to?(:authentication_keys) ? self.authentication_keys.include?(:email) : true + skip_email = options[:skip_email] || !have_email - apply_schema :email, String, :null => null, :limit => 100 + apply_schema :email, String, :null => null, :limit => 100 unless skip_email apply_schema :encrypted_password, String, :null => null, :limit => Devise::ENCRYPTORS_LENGTH[encryptor] apply_schema :password_salt, String, :null => null, :limit => 20 end