summaryrefslogtreecommitdiff
path: root/lib/gitlab/ci/config/entry/current_variables.rb
blob: 3b6721ec92d70c4c856959491a53c333a7dfe42a (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 CI/CD variables.
        # The class will be renamed to `Variables` when removing the FF `ci_variables_refactoring_to_variable`.
        #
        class CurrentVariables < ::Gitlab::Config::Entry::ComposableHash
          include ::Gitlab::Config::Entry::Validatable

          validations do
            validates :config, type: Hash
          end

          # Enable these lines when removing the FF `ci_variables_refactoring_to_variable`
          # and renaming this class to `Variables`.
          # def self.default(**)
          #   {}
          # end

          def value
            @entries.to_h do |key, entry|
              [key.to_s, entry.value]
            end
          end

          def value_with_data
            @entries.to_h do |key, entry|
              [key.to_s, entry.value_with_data]
            end
          end

          private

          def composable_class(_name, _config)
            Entry::Variable
          end

          def composable_metadata
            { allowed_value_data: opt(:allowed_value_data) }
          end
        end
      end
    end
  end
end