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

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

module Gitlab
  module Ci
    module Components
      ##
      # Components::Header class represents full component specification that is being prepended as first YAML document
      # in the CI Component file.
      #
      class Header
        attr_reader :errors

        def initialize(header)
          @header = header
          @errors = []
        end

        def empty?
          inputs_spec.to_h.empty?
        end

        def inputs(args)
          @input ||= Ci::Input::Inputs.new(inputs_spec, args)
        end

        def context(args)
          inputs(args).then do |input|
            raise ArgumentError unless input.valid?

            Ci::Interpolation::Context.new({ inputs: input.to_hash })
          end
        end

        private

        def inputs_spec
          @header.dig(:spec, :inputs)
        end
      end
    end
  end
end