summaryrefslogtreecommitdiff
path: root/lib/gitlab/ci/config/normalizer/factory.rb
blob: bf813f8e8785969ed20c7689b8e5aba6636e4a09 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# frozen_string_literal: true

module Gitlab
  module Ci
    class Config
      class Normalizer
        class Factory
          include Gitlab::Utils::StrongMemoize

          def initialize(name, config)
            @name = name
            @config = config
          end

          def create
            return [] unless strategy

            strategy.build_from(@name, @config)
          end

          private

          def strategy
            strong_memoize(:strategy) do
              strategies.find do |strategy|
                strategy.applies_to?(@config)
              end
            end
          end

          def strategies
            [NumberStrategy, MatrixStrategy]
          end
        end
      end
    end
  end
end