diff options
author | Lin Jen-Shin <godfat@godfat.org> | 2017-11-17 15:27:16 +0300 |
---|---|---|
committer | Lin Jen-Shin <godfat@godfat.org> | 2017-11-17 20:01:53 +0300 |
commit | 9ac0c76b78cd04b2505924f003dd720a0f155959 (patch) | |
tree | 67af1f0be0b9d6b5fc42b27c5afe5516e2c7574c /lib/gitlab/ci | |
parent | 0af35d7e30e373b885bfddb30b14718d72d75ab0 (diff) |
Use StrongMemoize and enable/disable cops properly
Diffstat (limited to 'lib/gitlab/ci')
-rw-r--r-- | lib/gitlab/ci/charts.rb | 3 | ||||
-rw-r--r-- | lib/gitlab/ci/config/entry/configurable.rb | 7 | ||||
-rw-r--r-- | lib/gitlab/ci/config/entry/node.rb | 6 | ||||
-rw-r--r-- | lib/gitlab/ci/config/entry/validatable.rb | 3 | ||||
-rw-r--r-- | lib/gitlab/ci/pipeline/chain/helpers.rb | 18 |
5 files changed, 19 insertions, 18 deletions
diff --git a/lib/gitlab/ci/charts.rb b/lib/gitlab/ci/charts.rb index fe2fd08a67a..e94166aee0c 100644 --- a/lib/gitlab/ci/charts.rb +++ b/lib/gitlab/ci/charts.rb @@ -2,12 +2,11 @@ module Gitlab module Ci module Charts module DailyInterval - # rubocop:disable Cop/ModuleWithInstanceVariables def grouped_count(query) query .group("DATE(#{::Ci::Pipeline.table_name}.created_at)") .count(:created_at) - .transform_keys { |date| date.strftime(@format) } + .transform_keys { |date| date.strftime(@format) } # rubocop:disable Cop/ModuleWithInstanceVariables end def interval_step diff --git a/lib/gitlab/ci/config/entry/configurable.rb b/lib/gitlab/ci/config/entry/configurable.rb index 2c96e5f65d7..63b803c15af 100644 --- a/lib/gitlab/ci/config/entry/configurable.rb +++ b/lib/gitlab/ci/config/entry/configurable.rb @@ -24,21 +24,20 @@ module Gitlab end end - # rubocop:disable Cop/ModuleWithInstanceVariables def compose!(deps = nil) return unless valid? self.class.nodes.each do |key, factory| factory - .value(@config[key]) + .value(config[key]) .with(key: key, parent: self) - @entries[key] = factory.create! + entries[key] = factory.create! end yield if block_given? - @entries.each_value do |entry| + entries.each_value do |entry| entry.compose!(deps) end end diff --git a/lib/gitlab/ci/config/entry/node.rb b/lib/gitlab/ci/config/entry/node.rb index c868943c42e..1fba0b2db0b 100644 --- a/lib/gitlab/ci/config/entry/node.rb +++ b/lib/gitlab/ci/config/entry/node.rb @@ -90,6 +90,12 @@ module Gitlab def self.aspects @aspects ||= [] end + + private + + def entries + @entries + end end end end diff --git a/lib/gitlab/ci/config/entry/validatable.rb b/lib/gitlab/ci/config/entry/validatable.rb index 1850c652c09..0dc359a86c3 100644 --- a/lib/gitlab/ci/config/entry/validatable.rb +++ b/lib/gitlab/ci/config/entry/validatable.rb @@ -12,9 +12,8 @@ module Gitlab end end - # rubocop:disable Cop/ModuleWithInstanceVariables def errors - @validator.messages + descendants.flat_map(&:errors) + @validator.messages + descendants.flat_map(&:errors) # rubocop:disable Cop/ModuleWithInstanceVariables end class_methods do diff --git a/lib/gitlab/ci/pipeline/chain/helpers.rb b/lib/gitlab/ci/pipeline/chain/helpers.rb index 36ed87dbd32..7ab7a64c7e3 100644 --- a/lib/gitlab/ci/pipeline/chain/helpers.rb +++ b/lib/gitlab/ci/pipeline/chain/helpers.rb @@ -3,21 +3,19 @@ module Gitlab module Pipeline module Chain module Helpers - # rubocop:disable Cop/ModuleWithInstanceVariables - def branch_exists? - return @is_branch if defined?(@is_branch) + include Gitlab::Utils::StrongMemoize - @is_branch = project.repository.branch_exists?(pipeline.ref) + def branch_exists? + strong_memoize(:is_branch) do + project.repository.branch_exists?(pipeline.ref) + end end - # rubocop:enable Cop/ModuleWithInstanceVariables - # rubocop:disable Cop/ModuleWithInstanceVariables def tag_exists? - return @is_tag if defined?(@is_tag) - - @is_tag = project.repository.tag_exists?(pipeline.ref) + strong_memoize(:is_tag) do + project.repository.tag_exists?(pipeline.ref) + end end - # rubocop:enable Cop/ModuleWithInstanceVariables def error(message) pipeline.errors.add(:base, message) |