diff --git a/lib/devise/controllers/helpers.rb b/lib/devise/controllers/helpers.rb index 0b717f3e1a..93b0aea13a 100644 --- a/lib/devise/controllers/helpers.rb +++ b/lib/devise/controllers/helpers.rb @@ -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 diff --git a/lib/devise/models/authenticatable.rb b/lib/devise/models/authenticatable.rb index 95e5e9b060..037cbe9666 100644 --- a/lib/devise/models/authenticatable.rb +++ b/lib/devise/models/authenticatable.rb @@ -27,13 +27,11 @@ module Models # 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, diff --git a/lib/devise/models/confirmable.rb b/lib/devise/models/confirmable.rb index 358276f6ff..bcda7e945e 100644 --- a/lib/devise/models/confirmable.rb +++ b/lib/devise/models/confirmable.rb @@ -29,15 +29,12 @@ module Models # 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 diff --git a/lib/devise/models/http_authenticatable.rb b/lib/devise/models/http_authenticatable.rb index 9d7f967cf9..7df43b1ba9 100644 --- a/lib/devise/models/http_authenticatable.rb +++ b/lib/devise/models/http_authenticatable.rb @@ -6,9 +6,7 @@ module Models # 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. diff --git a/lib/devise/models/lockable.rb b/lib/devise/models/lockable.rb index dcc2b5e09a..5a7a9880af 100644 --- a/lib/devise/models/lockable.rb +++ b/lib/devise/models/lockable.rb @@ -18,14 +18,9 @@ module Models # 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 diff --git a/lib/devise/models/recoverable.rb b/lib/devise/models/recoverable.rb index f113d12ce1..a50cd1d226 100644 --- a/lib/devise/models/recoverable.rb +++ b/lib/devise/models/recoverable.rb @@ -14,11 +14,7 @@ module Models # # 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. diff --git a/lib/devise/models/rememberable.rb b/lib/devise/models/rememberable.rb index 6657eb5208..31040aa9c2 100644 --- a/lib/devise/models/rememberable.rb +++ b/lib/devise/models/rememberable.rb @@ -30,14 +30,11 @@ module Models # # 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. diff --git a/lib/devise/models/timeoutable.rb b/lib/devise/models/timeoutable.rb index 764eac2b0f..a922797b3b 100644 --- a/lib/devise/models/timeoutable.rb +++ b/lib/devise/models/timeoutable.rb @@ -11,9 +11,7 @@ module Models # # 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) diff --git a/lib/devise/models/token_authenticatable.rb b/lib/devise/models/token_authenticatable.rb index 501fef4d3d..78da975fae 100644 --- a/lib/devise/models/token_authenticatable.rb +++ b/lib/devise/models/token_authenticatable.rb @@ -18,11 +18,10 @@ module Models # 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").