Class: Gitlab::Ci::Pipeline::Expression::Lexeme::Matches

Inherits:
LogicalOperator show all
Defined in:
lib/gitlab/ci/pipeline/expression/lexeme/matches.rb

Constant Summary collapse

PATTERN =
/=~/.freeze

Constants inherited from Operator

Operator::OperatorError

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from LogicalOperator

#initialize, #inspect, type

Methods inherited from Operator

type

Methods inherited from Base

consume?, #name, pattern, scan

Constructor Details

This class inherits a constructor from Gitlab::Ci::Pipeline::Expression::Lexeme::LogicalOperator

Class Method Details

.build(_value, behind, ahead) ⇒ Object


19
20
21
# File 'lib/gitlab/ci/pipeline/expression/lexeme/matches.rb', line 19

def self.build(_value, behind, ahead)
  new(behind, ahead)
end

.precedenceObject


23
24
25
# File 'lib/gitlab/ci/pipeline/expression/lexeme/matches.rb', line 23

def self.precedence
  10 # See: https://ruby-doc.org/core-2.5.0/doc/syntax/precedence_rdoc.html
end

Instance Method Details

#evaluate(variables = {}) ⇒ Object


11
12
13
14
15
16
17
# File 'lib/gitlab/ci/pipeline/expression/lexeme/matches.rb', line 11

def evaluate(variables = {})
  text = @left.evaluate(variables)
  regexp = @right.evaluate(variables)
  return false unless regexp

  regexp.scan(text.to_s).present?
end