Class: Codeowners::Checker::Group::Line

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

Overview

It sorts lines from CODEOWNERS file to different line types and holds shared methods for all lines.

Direct Known Subclasses

Comment, Empty, Pattern, UnrecognizedLine

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(line) ⇒ Line

Returns a new instance of Line.



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

def initialize(line)
  @line = line
end

Instance Attribute Details

#parentObject

Returns the value of attribute parent.



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

def parent
  @parent
end

Class Method Details

.build(line) ⇒ Object



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

def self.build(line)
  subclasses.each do |klass|
    return klass.new(line) if klass.match?(line)
  end
  UnrecognizedLine.new(line)
end

.subclassesObject



19
20
21
# File 'lib/codeowners/checker/group/line.rb', line 19

def self.subclasses
  [Empty, GroupBeginComment, GroupEndComment, Comment, Pattern]
end

Instance Method Details

#<=>(other) ⇒ Object



58
59
60
# File 'lib/codeowners/checker/group/line.rb', line 58

def <=>(other)
  to_s <=> other.to_s
end

#==(other) ⇒ Object



52
53
54
55
56
# File 'lib/codeowners/checker/group/line.rb', line 52

def ==(other)
  return false unless other.is_a?(self.class)

  other.to_s == to_s
end

#pattern?Boolean

Returns:

  • (Boolean)


39
40
41
# File 'lib/codeowners/checker/group/line.rb', line 39

def pattern?
  is_a?(Pattern)
end

#remove!Object



47
48
49
50
# File 'lib/codeowners/checker/group/line.rb', line 47

def remove!
  parent&.remove(self)
  self.parent = nil
end

#to_contentObject



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

def to_content
  to_s
end

#to_fileObject



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

def to_file
  to_s
end

#to_sObject



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

def to_s
  @line
end

#to_tree(indentation) ⇒ Object



43
44
45
# File 'lib/codeowners/checker/group/line.rb', line 43

def to_tree(indentation)
  indentation + to_s
end