Class: Gitlab::Ci::Config::Yaml::Loader

Inherits:
Object
  • Object
show all
Includes:
Utils::StrongMemoize
Defined in:
lib/gitlab/ci/config/yaml/loader.rb

Constant Summary collapse

AVAILABLE_TAGS =
[Config::Yaml::Tags::Reference].freeze
MAX_DOCUMENTS =
2

Instance Method Summary collapse

Constructor Details

#initialize(content, inputs: {}, variables: []) ⇒ Loader

Returns a new instance of Loader.



13
14
15
16
17
# File 'lib/gitlab/ci/config/yaml/loader.rb', line 13

def initialize(content, inputs: {}, variables: [])
  @content = content
  @inputs = inputs
  @variables = variables
end

Instance Method Details

#loadObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/gitlab/ci/config/yaml/loader.rb', line 19

def load
  yaml_result = load_uninterpolated_yaml

  return yaml_result unless yaml_result.valid?

  interpolator = Interpolation::Interpolator.new(yaml_result, inputs, variables)

  interpolator.interpolate!

  if interpolator.valid?
    Yaml::Result.new(config: interpolator.to_hash, error: nil, interpolated: interpolator.interpolated?)
  else
    Yaml::Result.new(error: interpolator.error_message, interpolated: interpolator.interpolated?)
  end
rescue ::Gitlab::Config::Loader::FormatError => e
  Yaml::Result.new(error: e.message, error_class: e)
end

#load_uninterpolated_yamlObject



37
38
39
40
41
# File 'lib/gitlab/ci/config/yaml/loader.rb', line 37

def load_uninterpolated_yaml
  Yaml::Result.new(config: load_yaml!, error: nil)
rescue ::Gitlab::Config::Loader::FormatError => e
  Yaml::Result.new(error: e.message, error_class: e)
end