Welcome to mirror list, hosted at ThFree Co, Russian Federation.

base.rb « functions « interpolation « config « ci « gitlab « lib - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: b04152a1558b135843f7cbed88c371fbc429c9c1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# frozen_string_literal: true

module Gitlab
  module Ci
    class Config
      module Interpolation
        module Functions
          class Base
            attr_reader :errors

            def self.function_expression_pattern
              raise NotImplementedError
            end

            def self.name
              raise NotImplementedError
            end

            def self.matches?(function_expression)
              function_expression_pattern.match?(function_expression)
            end

            def initialize(function_expression, ctx)
              @errors = []
              @function_args = parse_args(function_expression)
              @ctx = ctx
            end

            def valid?
              errors.empty?
            end

            def execute(_input_value)
              raise NotImplementedError
            end

            private

            attr_reader :function_args, :ctx

            def error(message)
              errors << "error in `#{self.class.name}` function: #{message}"
              nil
            end

            def parse_args(function_expression)
              self.class.function_expression_pattern.match(function_expression)
            end
          end
        end
      end
    end
  end
end