debian-mirror-gitlab/lib/gitlab/ci/environment_matcher.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

40 lines
745 B
Ruby
Raw Normal View History

2023-03-04 22:38:38 +05:30
# 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