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: {}, context: nil) ⇒ 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: {}, context: nil)
  @content = content
  @inputs = inputs
  @context = context
end

Instance Method Details

#loadObject



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

def load
  yaml_result = load_uninterpolated_yaml

  return yaml_result unless yaml_result.valid?

  variables = context&.variables || []
  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



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

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