Class: Gitlab::Ci::Pipeline::Expression::Lexeme::Pattern

Inherits:
Value
  • Object
show all
Defined in:
lib/gitlab/ci/pipeline/expression/lexeme/pattern.rb

Constant Summary collapse

PATTERN =
%r{^\/([^\/]|\\/)+[^\\]\/[ismU]*}.freeze

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Value

type

Methods inherited from Base

consume?, #name, scan

Constructor Details

#initialize(regexp) ⇒ Pattern

Returns a new instance of Pattern.


13
14
15
16
17
18
19
# File 'lib/gitlab/ci/pipeline/expression/lexeme/pattern.rb', line 13

def initialize(regexp)
  super(regexp.gsub(/\\\//, '/'))

  unless Gitlab::UntrustedRegexp::RubySyntax.valid?(@value)
    raise Lexer::SyntaxError, 'Invalid regular expression!'
  end
end

Class Method Details

.build(string) ⇒ Object


35
36
37
# File 'lib/gitlab/ci/pipeline/expression/lexeme/pattern.rb', line 35

def self.build(string)
  new(string)
end

.patternObject


31
32
33
# File 'lib/gitlab/ci/pipeline/expression/lexeme/pattern.rb', line 31

def self.pattern
  PATTERN
end

Instance Method Details

#evaluate(variables = {}) ⇒ Object


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

def evaluate(variables = {})
  Gitlab::UntrustedRegexp::RubySyntax.fabricate!(@value)
rescue RegexpError
  raise Expression::RuntimeError, 'Invalid regular expression!'
end

#inspectObject


27
28
29
# File 'lib/gitlab/ci/pipeline/expression/lexeme/pattern.rb', line 27

def inspect
  "/#{value}/"
end