Class: Gitlab::Ci::Config::Interpolation::FunctionsStack

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

Overview

This class matches the given function string with a predefined function and then applies it to the input value.

Defined Under Namespace

Classes: Output

Constant Summary collapse

FUNCTIONS =
[
  Functions::Truncate
].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(function_expressions) ⇒ FunctionsStack

Returns a new instance of FunctionsStack.



24
25
26
27
# File 'lib/gitlab/ci/config/interpolation/functions_stack.rb', line 24

def initialize(function_expressions)
  @errors = []
  @functions = build_stack(function_expressions)
end

Instance Attribute Details

#errorsObject (readonly)

Returns the value of attribute errors.



22
23
24
# File 'lib/gitlab/ci/config/interpolation/functions_stack.rb', line 22

def errors
  @errors
end

Instance Method Details

#evaluate(input_value) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/gitlab/ci/config/interpolation/functions_stack.rb', line 33

def evaluate(input_value)
  return Output.new(nil, errors) unless valid?

  functions.reduce(Output.new(input_value, [])) do |output, function|
    break output unless output.success?

    output_value = function.execute(output.value)

    if function.valid?
      Output.new(output_value, [])
    else
      Output.new(nil, function.errors)
    end
  end
end

#valid?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/gitlab/ci/config/interpolation/functions_stack.rb', line 29

def valid?
  errors.none?
end