image.rb 1.0 KB
Newer Older
G
gfyoung 已提交
1 2
# frozen_string_literal: true

3 4 5
module Gitlab
  module Ci
    class Config
6
      module Entry
7 8 9
        ##
        # Entry that represents a Docker image.
        #
10 11
        class Image < ::Gitlab::Config::Entry::Node
          include ::Gitlab::Config::Entry::Validatable
12 13

          ALLOWED_KEYS = %i[name entrypoint].freeze
14 15

          validations do
16 17 18 19
            validates :config, hash_or_string: true
            validates :config, allowed_keys: ALLOWED_KEYS

            validates :name, type: String, presence: true
20
            validates :entrypoint, array_of_strings: true, allow_nil: true
21
          end
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41

          def hash?
            @config.is_a?(Hash)
          end

          def string?
            @config.is_a?(String)
          end

          def name
            value[:name]
          end

          def entrypoint
            value[:entrypoint]
          end

          def value
            return { name: @config } if string?
            return @config if hash?
42

43 44
            {}
          end
45 46 47 48 49
        end
      end
    end
  end
end