Class: Gitlab::Ci::Config::Interpolation::Interpolator
- Inherits:
-
Object
- Object
- Gitlab::Ci::Config::Interpolation::Interpolator
- Defined in:
- lib/gitlab/ci/config/interpolation/interpolator.rb
Overview
Performs CI config file interpolation, and surfaces all possible interpolation errors.
Instance Attribute Summary collapse
-
#args ⇒ Object
readonly
Returns the value of attribute args.
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
Instance Method Summary collapse
- #error_message ⇒ Object
-
#initialize(config, args) ⇒ Interpolator
constructor
A new instance of Interpolator.
- #interpolate! ⇒ Object
- #interpolated? ⇒ Boolean
- #to_hash ⇒ Object
- #valid? ⇒ Boolean
Constructor Details
#initialize(config, args) ⇒ Interpolator
Returns a new instance of Interpolator.
13 14 15 16 17 18 |
# File 'lib/gitlab/ci/config/interpolation/interpolator.rb', line 13 def initialize(config, args) @config = config @args = args.to_h @errors = [] @interpolated = false end |
Instance Attribute Details
#args ⇒ Object (readonly)
Returns the value of attribute args.
11 12 13 |
# File 'lib/gitlab/ci/config/interpolation/interpolator.rb', line 11 def args @args end |
#config ⇒ Object (readonly)
Returns the value of attribute config.
11 12 13 |
# File 'lib/gitlab/ci/config/interpolation/interpolator.rb', line 11 def config @config end |
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
11 12 13 |
# File 'lib/gitlab/ci/config/interpolation/interpolator.rb', line 11 def errors @errors end |
Instance Method Details
#error_message ⇒ Object
28 29 30 31 32 33 34 35 36 |
# File 'lib/gitlab/ci/config/interpolation/interpolator.rb', line 28 def # Interpolator can have multiple error messages, like: ["interpolation interrupted by errors", "unknown # interpolation key: `abc`"] ? # # We are joining them together into a single one, because only one error can be surfaced when an external # file gets included and is invalid. The limit to three error messages combined is more than required. # @errors.first(3).join(', ') end |
#interpolate! ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/gitlab/ci/config/interpolation/interpolator.rb', line 38 def interpolate! return @errors.push(config.error) unless config.valid? if inputs_without_header? return @errors.push( _('Given inputs not defined in the `spec` section of the included configuration file')) end return @result ||= config.content unless config.has_header? return @errors.concat(header.errors) unless header.valid? return @errors.concat(inputs.errors) unless inputs.valid? return @errors.concat(context.errors) unless context.valid? return @errors.concat(template.errors) unless template.valid? @interpolated = true @result ||= template.interpolated.to_h.deep_symbolize_keys end |
#interpolated? ⇒ Boolean
58 59 60 |
# File 'lib/gitlab/ci/config/interpolation/interpolator.rb', line 58 def interpolated? @interpolated end |
#to_hash ⇒ Object
24 25 26 |
# File 'lib/gitlab/ci/config/interpolation/interpolator.rb', line 24 def to_hash @result.to_h end |
#valid? ⇒ Boolean
20 21 22 |
# File 'lib/gitlab/ci/config/interpolation/interpolator.rb', line 20 def valid? @errors.none? end |