diff options
author | Lin Jen-Shin <godfat@godfat.org> | 2017-11-17 20:27:16 +0800 |
---|---|---|
committer | Lin Jen-Shin <godfat@godfat.org> | 2017-11-18 01:01:53 +0800 |
commit | 9ac0c76b78cd04b2505924f003dd720a0f155959 (patch) | |
tree | 67af1f0be0b9d6b5fc42b27c5afe5516e2c7574c /lib/tasks/gitlab/task_helpers.rb | |
parent | 0af35d7e30e373b885bfddb30b14718d72d75ab0 (diff) | |
download | gitlab-ce-9ac0c76b78cd04b2505924f003dd720a0f155959.tar.gz |
Use StrongMemoize and enable/disable cops properly
Diffstat (limited to 'lib/tasks/gitlab/task_helpers.rb')
-rw-r--r-- | lib/tasks/gitlab/task_helpers.rb | 19 |
1 files changed, 9 insertions, 10 deletions
diff --git a/lib/tasks/gitlab/task_helpers.rb b/lib/tasks/gitlab/task_helpers.rb index 2feacbb4a09..6723662703c 100644 --- a/lib/tasks/gitlab/task_helpers.rb +++ b/lib/tasks/gitlab/task_helpers.rb @@ -1,10 +1,13 @@ require 'rainbow/ext/string' +require 'gitlab/utils/strong_memoize' module Gitlab TaskFailedError = Class.new(StandardError) TaskAbortedByUserError = Class.new(StandardError) module TaskHelpers + include Gitlab::Utils::StrongMemoize + extend self # Ask if the user wants to continue @@ -104,19 +107,17 @@ module Gitlab Gitlab.config.gitlab.user end - # rubocop:disable Cop/ModuleWithInstanceVariables def gitlab_user? - return @is_gitlab_user unless @is_gitlab_user.nil? - - current_user = run_command(%w(whoami)).chomp - @is_gitlab_user = current_user == gitlab_user + strong_memoize(:is_gitlab_user) do + current_user = run_command(%w(whoami)).chomp + current_user == gitlab_user + end end - # rubocop:disable Cop/ModuleWithInstanceVariables def warn_user_is_not_gitlab - return if @warned_user_not_gitlab + return if gitlab_user? - unless gitlab_user? + strong_memoize(:warned_user_not_gitlab) do current_user = run_command(%w(whoami)).chomp puts " Warning ".color(:black).background(:yellow) @@ -124,8 +125,6 @@ module Gitlab puts " Things may work\/fail for the wrong reasons." puts " For correct results you should run this as user #{gitlab_user.color(:magenta)}." puts "" - - @warned_user_not_gitlab = true end end |