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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(block, data, ctx) ⇒ Block

Returns a new instance of Block.



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

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.



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

def ctx
  @ctx
end

#dataObject (readonly)

Returns the value of attribute data.



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

def data
  @data
end

#errorsObject (readonly)

Returns the value of attribute errors.



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

def errors
  @errors
end

Instance Method Details

#contentObject



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

def content
  data
end

#lengthObject



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

def length
  block.length
end

#to_sObject



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

def to_s
  block
end

#valid?Boolean

Returns:

  • (Boolean)


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

def valid?
  errors.none?
end

#valueObject

Raises:

  • (ArgumentError)


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

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

  @value
end