Class: Gitlab::Ci::Pipeline::Expression::Lexeme::Pattern
- Defined in:
- lib/gitlab/ci/pipeline/expression/lexeme/pattern.rb
Constant Summary collapse
- PATTERN =
%r{^\/([^\/]|\\/)+[^\\]\/[ismU]*}
Instance Attribute Summary
Attributes inherited from Value
Class Method Summary collapse
Instance Method Summary collapse
- #evaluate(variables = {}) ⇒ Object
-
#initialize(regexp) ⇒ Pattern
constructor
A new instance of Pattern.
- #inspect ⇒ Object
Methods inherited from Value
Methods inherited from Base
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(%r{\\/}, '/')) 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 |
.build_and_evaluate(data, variables = {}) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/gitlab/ci/pipeline/expression/lexeme/pattern.rb', line 39 def self.build_and_evaluate(data, variables = {}) return data if data.is_a?(Gitlab::UntrustedRegexp) begin new_pattern = build(data) rescue Lexer::SyntaxError return data end new_pattern.evaluate(variables) end |
.pattern ⇒ Object
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 |
#inspect ⇒ Object
27 28 29 |
# File 'lib/gitlab/ci/pipeline/expression/lexeme/pattern.rb', line 27 def inspect "/#{value}/" end |