blob: 7d7a7742f68a7bbab08acb04c0b23b785586acdb (
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
|
# frozen_string_literal: true
module Gitlab
module Ci
class EnvironmentMatcher
def initialize(pattern)
@pattern = pattern
end
def match?(environment)
return false if pattern.blank?
exact_match?(environment) || wildcard_match?(environment)
end
private
attr_reader :pattern, :match_type
def exact_match?(environment)
pattern == environment
end
def wildcard_match?(environment)
return false unless wildcard?
wildcard_regex.match?(environment)
end
def wildcard?
pattern.include?('*')
end
def wildcard_regex
@wildcard_regex ||= Regexp.new(pattern.gsub('*', '.*'))
end
end
end
end
|