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: 6b53adc3a578828317e4324b1376faaf162592cf (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
# frozen_string_literal: true

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

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

          def valid?
            error.nil?
          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