summaryrefslogtreecommitdiff
path: root/lib/gitlab/ci/pipeline/expression/lexeme/variable.rb
blob: 37643c8ef53c03e32a151c1acdf12f82c6a22b93 (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
module Gitlab
  module Ci
    module Pipeline
      module Expression
        module Lexeme
          class Variable < Lexeme::Value
            PATTERN = /\$(?<name>\w+)/.freeze

            def initialize(name)
              @name = name
            end

            def evaluate(variables = {})
              variables.with_indifferent_access.fetch(@name, nil)
            end

            def self.build(string)
              new(string.match(PATTERN)[:name])
            end
          end
        end
      end
    end
  end
end