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

PREFIX =
'$[['
PATTERN =
/(?<block>\$\[\[\s*(?<data>.*?)\s*\]\])/
MAX_FUNCTIONS =
3

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(block, data, ctx) ⇒ Block

Returns a new instance of Block.



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

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

  evaluate!
end

Instance Attribute Details

#blockObject (readonly)

Returns the value of attribute block.



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

def block
  @block
end

#ctxObject (readonly)

Returns the value of attribute ctx.



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

def ctx
  @ctx
end

#dataObject (readonly)

Returns the value of attribute data.



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

def data
  @data
end

#errorsObject (readonly)

Returns the value of attribute errors.



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

def errors
  @errors
end

Class Method Details

.match(data) ⇒ Object



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

def self.match(data)
  return data unless data.is_a?(String) && data.include?(PREFIX)

  data.gsub(PATTERN) do
    yield ::Regexp.last_match(1), ::Regexp.last_match(2)
  end
end

Instance Method Details

#contentObject



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

def content
  data
end

#valid?Boolean

Returns:

  • (Boolean)


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

def valid?
  errors.none?
end

#valueObject

Raises:

  • (ArgumentError)


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

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

  @value
end