Skip to content

Commit

Permalink
Extract list of both strategies into class constant
Browse files Browse the repository at this point in the history
  • Loading branch information
f3ndot authored and ulissesalmeida committed May 3, 2016
1 parent 07e907e commit 0252f0e
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/devise/models/lockable.rb
Expand Up @@ -155,6 +155,9 @@ def if_access_locked
end

module ClassMethods
# List of strategies that are enabled/supported if :both is used.
BOTH_STRATEGIES = [:time, :email]

# Attempt to find a user by its unlock keys. If a record is found, send new
# unlock instructions to it. If not user is found, returns a new user
# with an email not found error.
Expand Down Expand Up @@ -182,8 +185,7 @@ def unlock_access_by_token(unlock_token)
# Is the unlock enabled for the given unlock strategy?
def unlock_strategy_enabled?(strategy)
self.unlock_strategy == strategy ||
# only :time and :email are subsets of the :both strategy
(self.unlock_strategy == :both && [:time, :email].include?(strategy))
(self.unlock_strategy == :both && BOTH_STRATEGIES.include?(strategy))
end

# Is the lock enabled for the given lock strategy?
Expand Down

0 comments on commit 0252f0e

Please sign in to comment.