Module: Devise::Schema
- Included in:
- Orm::ActiveRecord::Schema, Orm::Mongoid::Schema
- Defined in:
- lib/devise/schema.rb
Overview
Holds devise schema information. To use it, just include its methods and overwrite the apply_schema method.
Instance Method Summary collapse
-
#apply_devise_schema(name, type, options = {}) ⇒ Object
Overwrite with specific modification to create your own schema.
-
#confirmable ⇒ Object
Creates confirmation_token, confirmed_at and confirmation_sent_at.
-
#database_authenticatable(options = {}) ⇒ Object
Creates email when enabled (on by default), encrypted_password and password_salt.
-
#encryptable ⇒ Object
Creates password salt for encryption support.
-
#lockable(options = {}) ⇒ Object
Creates failed_attempts, unlock_token and locked_at depending on the options given.
-
#recoverable(options = {}) ⇒ Object
Creates reset_password_token and reset_password_sent_at.
-
#rememberable(options = {}) ⇒ Object
Creates remember_token and remember_created_at.
-
#token_authenticatable ⇒ Object
Creates authentication_token.
-
#trackable ⇒ Object
Creates sign_in_count, current_sign_in_at, last_sign_in_at, current_sign_in_ip, last_sign_in_ip.
Instance Method Details
#apply_devise_schema(name, type, options = {}) ⇒ Object
Overwrite with specific modification to create your own schema.
98 99 100 |
# File 'lib/devise/schema.rb', line 98 def apply_devise_schema(name, type, ={}) raise NotImplementedError end |
#confirmable ⇒ Object
Creates confirmation_token, confirmed_at and confirmation_sent_at.
35 36 37 38 39 |
# File 'lib/devise/schema.rb', line 35 def confirmable apply_devise_schema :confirmation_token, String apply_devise_schema :confirmed_at, DateTime apply_devise_schema :confirmation_sent_at, DateTime end |
#database_authenticatable(options = {}) ⇒ Object
Creates email when enabled (on by default), encrypted_password and password_salt.
Options
-
:null - When true, allow columns to be null.
-
:default - Should be set to “” when :null is false.
Notes
For Datamapper compatibility, we explicitly hardcode the limit for the encrypter password field in 128 characters.
15 16 17 18 19 20 21 22 |
# File 'lib/devise/schema.rb', line 15 def database_authenticatable(={}) null = [:null] || false default = .key?(:default) ? [:default] : ("" if null == false) include_email = !respond_to?(:authentication_keys) || self.authentication_keys.include?(:email) apply_devise_schema :email, String, :null => null, :default => default if include_email apply_devise_schema :encrypted_password, String, :null => null, :default => default, :limit => 128 end |
#encryptable ⇒ Object
Creates password salt for encryption support.
25 26 27 |
# File 'lib/devise/schema.rb', line 25 def encryptable apply_devise_schema :password_salt, String end |
#lockable(options = {}) ⇒ Object
Creates failed_attempts, unlock_token and locked_at depending on the options given.
Options
-
:unlock_strategy - The strategy used for unlock. Can be :time, :email, :both (default), :none. If :email or :both, creates a unlock_token field.
-
:lock_strategy - The strategy used for locking. Can be :failed_attempts (default) or :none.
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/devise/schema.rb', line 77 def lockable(={}) unlock_strategy = [:unlock_strategy] unlock_strategy ||= self.unlock_strategy if respond_to?(:unlock_strategy) unlock_strategy ||= :both lock_strategy = [:lock_strategy] lock_strategy ||= self.lock_strategy if respond_to?(:lock_strategy) lock_strategy ||= :failed_attempts if lock_strategy == :failed_attempts apply_devise_schema :failed_attempts, Integer, :default => 0 end if [:both, :email].include?(unlock_strategy) apply_devise_schema :unlock_token, String end apply_devise_schema :locked_at, DateTime end |
#recoverable(options = {}) ⇒ Object
Creates reset_password_token and reset_password_sent_at.
Options
-
:reset_within - When true, adds a column that reset passwords within some date
45 46 47 48 49 |
# File 'lib/devise/schema.rb', line 45 def recoverable(={}) use_within = .fetch(:reset_within, Devise.reset_password_within.present?) apply_devise_schema :reset_password_token, String apply_devise_schema :reset_password_sent_at, DateTime if use_within end |
#rememberable(options = {}) ⇒ Object
Creates remember_token and remember_created_at.
Options
-
:use_salt - When true, does not create a remember_token and use password_salt instead.
55 56 57 58 59 |
# File 'lib/devise/schema.rb', line 55 def rememberable(={}) use_salt = .fetch(:use_salt, Devise.use_salt_as_remember_token) apply_devise_schema :remember_token, String unless use_salt apply_devise_schema :remember_created_at, DateTime end |
#token_authenticatable ⇒ Object
Creates authentication_token.
30 31 32 |
# File 'lib/devise/schema.rb', line 30 def token_authenticatable apply_devise_schema :authentication_token, String end |
#trackable ⇒ Object
Creates sign_in_count, current_sign_in_at, last_sign_in_at, current_sign_in_ip, last_sign_in_ip.
63 64 65 66 67 68 69 |
# File 'lib/devise/schema.rb', line 63 def trackable apply_devise_schema :sign_in_count, Integer, :default => 0 apply_devise_schema :current_sign_in_at, DateTime apply_devise_schema :last_sign_in_at, DateTime apply_devise_schema :current_sign_in_ip, String apply_devise_schema :last_sign_in_ip, String end |