Class: Codeowners::Checker::Group::Line
- Inherits:
-
Object
- Object
- Codeowners::Checker::Group::Line
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.
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(line) ⇒ Line
Returns a new instance of Line.
22
23
24
|
# File 'lib/codeowners/checker/group/line.rb', line 22
def initialize(line)
@line = line
end
|
Instance Attribute Details
#parent ⇒ Object
Returns the value of attribute parent.
9
10
11
|
# File 'lib/codeowners/checker/group/line.rb', line 9
def parent
@parent
end
|
Class Method Details
.build(line, transform_line_procs: nil) ⇒ Object
11
12
13
14
15
16
|
# File 'lib/codeowners/checker/group/line.rb', line 11
def self.build(line, transform_line_procs: nil)
subclasses.each do |klass|
return klass.new(line) if klass.match?(line)
end
UnrecognizedLine.new(line)
end
|
.subclasses ⇒ Object
18
19
20
|
# File 'lib/codeowners/checker/group/line.rb', line 18
def self.subclasses
[Empty, , , , Pattern]
end
|
Instance Method Details
#<=>(other) ⇒ Object
53
54
55
|
# File 'lib/codeowners/checker/group/line.rb', line 53
def <=>(other)
to_s <=> other.to_s
end
|
#==(other) ⇒ Object
47
48
49
50
51
|
# File 'lib/codeowners/checker/group/line.rb', line 47
def ==(other)
return false unless other.is_a?(self.class)
other.to_s == to_s
end
|
#normalize_path(file) ⇒ Object
71
72
73
74
|
# File 'lib/codeowners/checker/group/line.rb', line 71
def normalize_path(file)
Pathname.new(file)
.relative_path_from(Pathname.new('.')).to_s
end
|
#pattern? ⇒ Boolean
34
35
36
|
# File 'lib/codeowners/checker/group/line.rb', line 34
def pattern?
is_a?(Pattern)
end
|
#remove! ⇒ Object
42
43
44
45
|
# File 'lib/codeowners/checker/group/line.rb', line 42
def remove!
parent&.remove(self)
parent = nil
end
|
#suggest_files_for_pattern ⇒ Object
Pick all files from parent folder of pattern. This is used to build a list of suggestions case the pattern is not matching. If the pattern use “/” it will consider “.” If the pattern uses Static files, it tries to reach the parent. If the pattern revers to the root folder, pick all files from the current pattern dir.
64
65
66
67
68
69
|
# File 'lib/codeowners/checker/group/line.rb', line 64
def suggest_files_for_pattern
parent_folders = pattern.split('/')[0..-2]
parent_folders << '*' if parent_folders[-1] != '*'
files = Dir[File.join(*parent_folders)] || []
files.map(&method(:normalize_path))
end
|
#to_content ⇒ Object
30
31
32
|
# File 'lib/codeowners/checker/group/line.rb', line 30
def to_content
to_s
end
|
#to_s ⇒ Object
26
27
28
|
# File 'lib/codeowners/checker/group/line.rb', line 26
def to_s
@line
end
|
#to_tree(indentation) ⇒ Object
38
39
40
|
# File 'lib/codeowners/checker/group/line.rb', line 38
def to_tree(indentation)
indentation + to_s
end
|