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

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

module Gitlab
  module Ci
    class Config
      module Yaml
        class Result
          attr_reader :error, :error_class

          def initialize(config: nil, error: nil, error_class: nil, interpolated: false)
            @config = Array.wrap(config)
            @error = error
            @error_class = error_class
            @interpolated = interpolated
          end

          def valid?
            error.nil?
          end

          def interpolated?
            !!@interpolated
          end

          def has_header?
            return false unless @config.first.is_a?(Hash)

            @config.size > 1 && @config.first.key?(:spec)
          end

          def header
            raise ArgumentError unless has_header?

            @config.first
          end

          def content
            return @config.last if has_header?

            @config.first || {}
          end
        end
      end
    end
  end
end