Class: GitlabCodeownersChecker::Pattern

Inherits:
Object
  • Object
show all
Defined in:
lib/gitab_codeowners_checker/pattern.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pattern, owners) ⇒ Pattern

Returns a new instance of Pattern.



11
12
13
14
# File 'lib/gitab_codeowners_checker/pattern.rb', line 11

def initialize(pattern, owners)
  @pattern = pattern
  @owners = owners
end

Instance Attribute Details

#ownersObject (readonly)

Returns the value of attribute owners.



15
16
17
# File 'lib/gitab_codeowners_checker/pattern.rb', line 15

def owners
  @owners
end

#patternObject (readonly)

Returns the value of attribute pattern.



15
16
17
# File 'lib/gitab_codeowners_checker/pattern.rb', line 15

def pattern
  @pattern
end

Class Method Details

.from_file_line(str) ⇒ Object



5
6
7
8
9
# File 'lib/gitab_codeowners_checker/pattern.rb', line 5

def self.from_file_line(str)
  path, *owners = str.split(' ')
  pattern = path[-1] == '/' ? /\A#{Regexp.escape(path)}.+/ : path
  new(pattern, owners)
end

Instance Method Details

#match?(str) ⇒ Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/gitab_codeowners_checker/pattern.rb', line 17

def match?(str)
  @pattern.is_a?(Regexp) ? @pattern.match?(str) : str == @pattern
end