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

Instance Method Details

#apply_devise_schema(name, type, options = {}) ⇒ Object

Overwrite with specific modification to create your own schema.

Raises:

  • (NotImplementedError)


93
94
95
# File 'lib/devise/schema.rb', line 93

def apply_devise_schema(name, type, options={})
  raise NotImplementedError
end

#authenticatable(*args) ⇒ Object



6
7
8
9
# File 'lib/devise/schema.rb', line 6

def authenticatable(*args)
  ActiveSupport::Deprecation.warn "t.authenticatable in migrations is deprecated. Please use t.database_authenticatable instead.", caller
  database_authenticatable(*args)
end

#confirmableObject

Creates confirmation_token, confirmed_at and confirmation_sent_at.



39
40
41
42
43
# File 'lib/devise/schema.rb', line 39

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, 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.



20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/devise/schema.rb', line 20

def database_authenticatable(options={})
  null    = options[:null] || false
  default = options.key?(:default) ? options[:default] : ("" if null == false)

  if options.delete(:encryptor)
    ActiveSupport::Deprecation.warn ":encryptor as option is deprecated, simply remove it."
  end

  apply_devise_schema :email,              String, :null => null, :default => default
  apply_devise_schema :encrypted_password, String, :null => null, :default => default, :limit => 128
  apply_devise_schema :password_salt,      String, :null => null, :default => default
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.



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/devise/schema.rb', line 72

def lockable(options={})
  unlock_strategy   = options[:unlock_strategy]
  unlock_strategy ||= self.unlock_strategy if respond_to?(:unlock_strategy)
  unlock_strategy ||= :both

  lock_strategy   = options[: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

#recoverableObject

Creates reset_password_token.



46
47
48
# File 'lib/devise/schema.rb', line 46

def recoverable
  apply_devise_schema :reset_password_token, String
end

#rememberableObject

Creates remember_token and remember_created_at.



51
52
53
54
# File 'lib/devise/schema.rb', line 51

def rememberable
  apply_devise_schema :remember_token,      String
  apply_devise_schema :remember_created_at, DateTime
end

#token_authenticatable(options = {}) ⇒ Object

Creates authentication_token.



34
35
36
# File 'lib/devise/schema.rb', line 34

def token_authenticatable(options={})
  apply_devise_schema :authentication_token, String
end

#trackableObject

Creates sign_in_count, current_sign_in_at, last_sign_in_at, current_sign_in_ip, last_sign_in_ip.



58
59
60
61
62
63
64
# File 'lib/devise/schema.rb', line 58

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