Class: Codeowners::Checker::Group::Pattern

Inherits:
Line
  • Object
show all
Defined in:
lib/codeowners/checker/group/pattern.rb

Overview

Defines and manages line type pattern.

Instance Attribute Summary collapse

Attributes inherited from Line

#parent

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Line

#<=>, #==, build, #normalize_path, #pattern?, #remove!, subclasses, #suggest_files_for_pattern, #to_content, #to_tree

Constructor Details

#initialize(line) ⇒ Pattern

Returns a new instance of Pattern.



17
18
19
20
# File 'lib/codeowners/checker/group/pattern.rb', line 17

def initialize(line)
  super
  parse(line)
end

Instance Attribute Details

#ownersObject

Returns the value of attribute owners.



10
11
12
# File 'lib/codeowners/checker/group/pattern.rb', line 10

def owners
  @owners
end

#patternObject

Returns the value of attribute pattern.



10
11
12
# File 'lib/codeowners/checker/group/pattern.rb', line 10

def pattern
  @pattern
end

Class Method Details

.match?(line) ⇒ Boolean

Returns:

  • (Boolean)


12
13
14
15
# File 'lib/codeowners/checker/group/pattern.rb', line 12

def self.match?(line)
  _pattern, *owners = line.split(/\s+/)
  owners.any? && owners.all? { |owner| owner.include?('@') }
end

Instance Method Details

#match_file?(file) ⇒ Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/codeowners/checker/group/pattern.rb', line 30

def match_file?(file)
  regex.match(file)
end

#ownerObject



22
23
24
# File 'lib/codeowners/checker/group/pattern.rb', line 22

def owner
  owners.first
end

#parse(line) ⇒ Object



26
27
28
# File 'lib/codeowners/checker/group/pattern.rb', line 26

def parse(line)
  @pattern, *@owners = line.split(/\s+/)
end

#to_sObject



34
35
36
# File 'lib/codeowners/checker/group/pattern.rb', line 34

def to_s
  [@pattern, @owners].join(' ')
end