diff options
author | Christian Couder <chriscool@tuxfamily.org> | 2019-09-06 14:57:10 +0200 |
---|---|---|
committer | Christian Couder <chriscool@tuxfamily.org> | 2019-09-07 17:31:23 +0200 |
commit | 4aa4449ef5109eb0784f63fe1b7a3fc15bea8497 (patch) | |
tree | 5716f462ad2715d41739a9c8cbd530b07f0f2c83 | |
parent | ec326ecf91e893531bc2412fd4177405911e0e98 (diff) | |
download | gitlab-ce-4aa4449ef5109eb0784f63fe1b7a3fc15bea8497.tar.gz |
Refactor parse_options() in push_options.rbreduce-parse-options-complexity
This improves code quality by reducing Cognitive Complexity.
This fixes https://gitlab.com/gitlab-org/gitlab-ce/issues/67091
-rw-r--r-- | lib/gitlab/push_options.rb | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/lib/gitlab/push_options.rb b/lib/gitlab/push_options.rb index a2296d265cd..93c0f3132d0 100644 --- a/lib/gitlab/push_options.rb +++ b/lib/gitlab/push_options.rb @@ -56,19 +56,23 @@ module Gitlab next if [namespace, key].any?(&:nil?) - options[namespace] ||= HashWithIndifferentAccess.new - - if option_multi_value?(namespace, key) - options[namespace][key] ||= HashWithIndifferentAccess.new(0) - options[namespace][key][value] += 1 - else - options[namespace][key] = value - end + store_option_info(options, namespace, key, value) end options end + def store_option_info(options, namespace, key, value) + options[namespace] ||= HashWithIndifferentAccess.new + + if option_multi_value?(namespace, key) + options[namespace][key] ||= HashWithIndifferentAccess.new(0) + options[namespace][key][value] += 1 + else + options[namespace][key] = value + end + end + def option_multi_value?(namespace, key) MULTI_VALUE_OPTIONS.any? { |arr| arr == [namespace, key] } end |