From 3079e44f12fd717a727c3dace16f3a7651891d5b Mon Sep 17 00:00:00 2001 From: Nathan Broadbent Date: Wed, 22 Nov 2017 02:28:20 +0700 Subject: [PATCH] Refactor check_for_lockup. Also check for the case where the engine is not mounted. --- lib/lockup.rb | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/lib/lockup.rb b/lib/lockup.rb index e9a701e..d236ff9 100644 --- a/lib/lockup.rb +++ b/lib/lockup.rb @@ -14,17 +14,10 @@ module Lockup private def check_for_lockup - if lockup_codeword_present? - if cookies[:lockup].present? - if cookies[:lockup] == lockup_codeword - return - else - redirect_to lockup.unlock_path(return_to: request.fullpath.split('?lockup_codeword')[0], lockup_codeword: params[:lockup_codeword]) - end - else - redirect_to lockup.unlock_path(return_to: request.fullpath.split('?lockup_codeword')[0], lockup_codeword: params[:lockup_codeword]) - end - end + return unless respond_to?(:lockup) && lockup_codeword_present? + return if cookies[:lockup].present? && cookies[:lockup] == lockup_codeword + + redirect_to lockup.unlock_path(return_to: request.fullpath.split('?lockup_codeword')[0], lockup_codeword: params[:lockup_codeword]) end def lockup_codeword_present?