Class: RefMatcher
- Inherits:
-
Object
- Object
- RefMatcher
- Defined in:
- app/models/ref_matcher.rb
Instance Method Summary collapse
-
#initialize(ref_name_or_pattern) ⇒ RefMatcher
constructor
A new instance of RefMatcher.
-
#matches?(ref_name) ⇒ Boolean
Checks if the protected ref matches the given ref name.
-
#matching(refs) ⇒ Object
Returns all branches/tags (among the given list of refs [‘Gitlab::Git::Branch`] or their names [`String`]) that match the current protected ref.
-
#wildcard? ⇒ Boolean
Checks if this protected ref contains a wildcard.
Constructor Details
#initialize(ref_name_or_pattern) ⇒ RefMatcher
Returns a new instance of RefMatcher.
4 5 6 |
# File 'app/models/ref_matcher.rb', line 4 def initialize(ref_name_or_pattern) @ref_name_or_pattern = ref_name_or_pattern end |
Instance Method Details
#matches?(ref_name) ⇒ Boolean
Checks if the protected ref matches the given ref name.
15 16 17 18 19 |
# File 'app/models/ref_matcher.rb', line 15 def matches?(ref_name) return false if @ref_name_or_pattern.blank? exact_match?(ref_name) || wildcard_match?(ref_name) end |
#matching(refs) ⇒ Object
Returns all branches/tags (among the given list of refs [‘Gitlab::Git::Branch`] or their names [`String`]) that match the current protected ref.
10 11 12 |
# File 'app/models/ref_matcher.rb', line 10 def matching(refs) refs.select { |ref| ref.is_a?(String) ? matches?(ref) : matches?(ref.name) } end |
#wildcard? ⇒ Boolean
Checks if this protected ref contains a wildcard
22 23 24 |
# File 'app/models/ref_matcher.rb', line 22 def wildcard? @ref_name_or_pattern && @ref_name_or_pattern.include?('*') end |