Class: Gitlab::Ci::Config::Interpolation::Block

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab/ci/config/interpolation/block.rb

Overview

This class represents an interpolation block. The format supported is: $[[ <access> | <function1> | <function2> | … <functionN> ]]

<access> specifies the value to retrieve (e.g. inputs.key). <function> can be optionally provided with or without arguments to manipulate the access value. Functions are evaluated in the order they are presented.

Constant Summary collapse

MAX_FUNCTIONS =
3
SKIP_INTERPOLATION_CONTEXTS =
%w[matrix].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(block, data, ctx) ⇒ Block

Returns a new instance of Block.



21
22
23
24
25
26
27
28
29
# File 'lib/gitlab/ci/config/interpolation/block.rb', line 21

def initialize(block, data, ctx)
  @block = block
  @data = data
  @ctx = ctx
  @errors = []
  @value = nil

  evaluate!
end

Instance Attribute Details

#ctxObject (readonly)

Returns the value of attribute ctx.



19
20
21
# File 'lib/gitlab/ci/config/interpolation/block.rb', line 19

def ctx
  @ctx
end

#dataObject (readonly)

Returns the value of attribute data.



19
20
21
# File 'lib/gitlab/ci/config/interpolation/block.rb', line 19

def data
  @data
end

#errorsObject (readonly)

Returns the value of attribute errors.



19
20
21
# File 'lib/gitlab/ci/config/interpolation/block.rb', line 19

def errors
  @errors
end

Instance Method Details

#contentObject



35
36
37
# File 'lib/gitlab/ci/config/interpolation/block.rb', line 35

def content
  data
end

#lengthObject



45
46
47
# File 'lib/gitlab/ci/config/interpolation/block.rb', line 45

def length
  block.length
end

#to_sObject



49
50
51
# File 'lib/gitlab/ci/config/interpolation/block.rb', line 49

def to_s
  block
end

#valid?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/gitlab/ci/config/interpolation/block.rb', line 31

def valid?
  errors.none?
end

#valueObject

Raises:

  • (ArgumentError)


39
40
41
42
43
# File 'lib/gitlab/ci/config/interpolation/block.rb', line 39

def value
  raise ArgumentError, 'block invalid' unless valid?

  @value
end