Use ActiveSupport::Concern.

This commit is contained in:
José Valim 2010-02-17 12:35:38 +01:00
parent 8e21373946
commit 691f9324f5
9 changed files with 28 additions and 51 deletions

View File

@ -2,17 +2,16 @@ module Devise
module Controllers
# Those helpers are convenience methods added to ApplicationController.
module Helpers
extend ActiveSupport::Concern
def self.included(base)
base.class_eval do
helper_method :warden, :signed_in?, :devise_controller?,
*Devise.mappings.keys.map { |m| [:"current_#{m}", :"#{m}_signed_in?"] }.flatten
included do
helper_method :warden, :signed_in?, :devise_controller?,
*Devise.mappings.keys.map { |m| [:"current_#{m}", :"#{m}_signed_in?"] }.flatten
# Use devise default_url_options. We have to declare it here to overwrite
# default definitions.
def default_url_options(options=nil)
Devise::Mapping.default_url_options
end
# Use devise default_url_options. We have to declare it here to overwrite
# default definitions.
def default_url_options(options=nil)
Devise::Mapping.default_url_options
end
end

View File

@ -27,13 +27,11 @@ module Devise
# User.find(1).valid_password?('password123') # returns true/false
#
module Authenticatable
def self.included(base)
base.class_eval do
extend ClassMethods
extend ActiveSupport::Concern
attr_reader :password, :current_password
attr_accessor :password_confirmation
end
included do
attr_reader :password, :current_password
attr_accessor :password_confirmation
end
# Regenerates password salt and encrypted password each time password is set,

View File

@ -29,15 +29,12 @@ module Devise
# User.find(1).send_confirmation_instructions # manually send instructions
# User.find(1).resend_confirmation! # generates a new token and resent it
module Confirmable
extend ActiveSupport::Concern
include Devise::Models::Activatable
def self.included(base)
base.class_eval do
extend ClassMethods
before_create :generate_confirmation_token, :if => :confirmation_required?
after_create :send_confirmation_instructions, :if => :confirmation_required?
end
included do
before_create :generate_confirmation_token, :if => :confirmation_required?
after_create :send_confirmation_instructions, :if => :confirmation_required?
end
# Confirm a user by setting it's confirmed_at to actual time. If the user

View File

@ -6,9 +6,7 @@ module Devise
# model class responds to authenticate and authentication_keys methods
# (which for example are defined in authenticatable).
module HttpAuthenticatable
def self.included(base)
base.extend ClassMethods
end
extend ActiveSupport::Concern
module ClassMethods
# Authenticate an user using http.

View File

@ -18,14 +18,9 @@ module Devise
# available when unlock_strategy is :time or :both.
#
module Lockable
extend ActiveSupport::Concern
include Devise::Models::Activatable
def self.included(base)
base.class_eval do
extend ClassMethods
end
end
# Lock an user setting it's locked_at to actual time.
def lock
self.locked_at = Time.now

View File

@ -14,11 +14,7 @@ module Devise
# # creates a new token and send it with instructions about how to reset the password
# User.find(1).send_reset_password_instructions
module Recoverable
def self.included(base)
base.class_eval do
extend ClassMethods
end
end
extend ActiveSupport::Concern
# Update password saving the record and clearing token. Returns true if
# the passwords are valid and the record was saved, false otherwise.

View File

@ -30,14 +30,11 @@ module Devise
# # lookup the user based on the incoming cookie information
# User.serialize_from_cookie(cookie_string)
module Rememberable
extend ActiveSupport::Concern
def self.included(base)
base.class_eval do
extend ClassMethods
# Remember me option available in after_authentication hook.
attr_accessor :remember_me
end
included do
# Remember me option available in after_authentication hook.
attr_accessor :remember_me
end
# Generate a new remember token and save the record without validations.

View File

@ -11,9 +11,7 @@ module Devise
#
# timeout_in: the time you want to timeout the user session without activity.
module Timeoutable
def self.included(base)
base.extend ClassMethods
end
extend ActiveSupport::Concern
# Checks whether the user session has expired based on configured time.
def timedout?(last_access)

View File

@ -18,11 +18,10 @@ module Devise
# User.find(1).valid_authentication_token?('rI1t6PKQ8yP7VetgwdybB') # returns true/false
#
module TokenAuthenticatable
def self.included(base)
base.class_eval do
extend ClassMethods
before_save :ensure_authentication_token
end
extend ActiveSupport::Concern
included do
before_save :ensure_authentication_token
end
# Generate new authentication token (a.k.a. "single access token").