Welcome to mirror list, hosted at ThFree Co, Russian Federation.

number_strategy.rb « normalizer « config « ci « gitlab « lib - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 4754e7b46d4887067d738086533f7a72035e514e (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
39
40
41
42
43
44
45
46
47
# frozen_string_literal: true

module Gitlab
  module Ci
    class Config
      class Normalizer
        class NumberStrategy
          class << self
            def applies_to?(config)
              config.is_a?(Integer) || config.is_a?(Hash) && config.key?(:number)
            end

            def build_from(job_name, config)
              total = config.is_a?(Hash) ? config[:number] : config

              Array.new(total) do |index|
                new(job_name, index.next, total)
              end
            end
          end

          def initialize(job_name, instance, total)
            @job_name = job_name
            @instance = instance
            @total = total
          end

          def attributes
            {
              name: name,
              instance: instance,
              parallel: { total: total }
            }
          end

          def name
            "#{job_name} #{instance}/#{total}"
          end

          private

          attr_reader :job_name, :instance, :total
        end
      end
    end
  end
end