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

variables.rb « entry « config « ci « gitlab « lib - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: dc164d752be96efa94f47122885dba1c63d88ff5 (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
48
49
# frozen_string_literal: true

module Gitlab
  module Ci
    class Config
      module Entry
        ##
        # Entry that represents environment variables.
        #
        class Variables < ::Gitlab::Config::Entry::Node
          include ::Gitlab::Config::Entry::Validatable

          ALLOWED_VALUE_DATA = %i[value description].freeze

          validations do
            validates :config, variables: { allowed_value_data: ALLOWED_VALUE_DATA }, if: :use_value_data?
            validates :config, variables: true, unless: :use_value_data?
          end

          def value
            Hash[@config.map { |key, value| [key.to_s, expand_value(value)[:value]] }]
          end

          def self.default(**)
            {}
          end

          def value_with_data
            Hash[@config.map { |key, value| [key.to_s, expand_value(value)] }]
          end

          def use_value_data?
            opt(:use_value_data)
          end

          private

          def expand_value(value)
            if value.is_a?(Hash)
              { value: value[:value].to_s, description: value[:description] }
            else
              { value: value.to_s, description: nil }
            end
          end
        end
      end
    end
  end
end