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

default.rb « arguments « input « ci « gitlab « lib - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: c6762b0487091c9a52cb0321c08947346a518688 (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
# frozen_string_literal: true

module Gitlab
  module Ci
    module Input
      module Arguments
        ##
        # Input::Arguments::Default class represents user-provided input argument that has a default value.
        #
        class Default < Input::Arguments::Base
          def validate!
            return error('argument specification invalid') unless spec.key?(:default)

            error('invalid default value') unless default.is_a?(String) || default.nil?
          end

          ##
          # User-provided value needs to be specified, but it may be an empty string:
          #
          # ```yaml
          # inputs:
          #   env:
          #     default: development
          #
          # with:
          #   env: ""
          # ```
          #
          # The configuration above will result in `env` being an empty string.
          #
          def to_value
            value.nil? ? default : value
          end

          def default
            spec[:default]
          end

          def self.matches?(spec)
            return false unless spec.is_a?(Hash)

            spec.count == 1 && spec.each_key.first == :default
          end
        end
      end
    end
  end
end