diff options
Diffstat (limited to 'ruby/lib/gitlab/ref_matcher.rb')
-rw-r--r-- | ruby/lib/gitlab/ref_matcher.rb | 41 |
1 files changed, 0 insertions, 41 deletions
diff --git a/ruby/lib/gitlab/ref_matcher.rb b/ruby/lib/gitlab/ref_matcher.rb deleted file mode 100644 index c0bb2163a..000000000 --- a/ruby/lib/gitlab/ref_matcher.rb +++ /dev/null @@ -1,41 +0,0 @@ -# frozen_string_literal: true - -module GitLab - class RefMatcher - def initialize(ref_name_or_pattern) - @ref_name_or_pattern = ref_name_or_pattern - end - - # Checks if the protected ref matches the given ref name. - def matches?(ref_name) - return false if @ref_name_or_pattern.blank? - - exact_match?(ref_name) || wildcard_match?(ref_name) - end - - private - - # Checks if this protected ref contains a wildcard - def wildcard? - @ref_name_or_pattern&.include?('*') - end - - def exact_match?(ref_name) - @ref_name_or_pattern == ref_name - end - - def wildcard_match?(ref_name) - return false unless wildcard? - - ref_name.match(wildcard_regex).present? - end - - def wildcard_regex - @wildcard_regex ||= begin - split = @ref_name_or_pattern.split('*', -1) # Use -1 to correctly handle trailing '*' - quoted_segments = split.map { |segment| Regexp.quote(segment) } - /\A#{quoted_segments.join('.*?')}\z/ - end - end - end -end |