lib/codeowners/checker/group/line.rb in codeowners-checker-1.0.0 vs lib/codeowners/checker/group/line.rb in codeowners-checker-1.0.1
- old
+ new
@@ -1,16 +1,17 @@
# frozen_string_literal: true
+require 'pathname'
module Codeowners
class Checker
class Group
# It sorts lines from CODEOWNERS file to different line types and holds
# shared methods for all lines.
class Line
attr_accessor :parent
- def self.build(line, transform_line_procs: nil)
+ def self.build(line)
subclasses.each do |klass|
return klass.new(line) if klass.match?(line)
end
UnrecognizedLine.new(line)
end
@@ -29,49 +30,34 @@
def to_content
to_s
end
+ def to_file
+ to_s
+ end
+
def pattern?
is_a?(Pattern)
end
def to_tree(indentation)
indentation + to_s
end
def remove!
parent&.remove(self)
- parent = nil
+ self.parent = nil
end
def ==(other)
return false unless other.is_a?(self.class)
other.to_s == to_s
end
def <=>(other)
to_s <=> other.to_s
- end
-
- # 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.
- 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
-
- def normalize_path(file)
- Pathname.new(file)
- .relative_path_from(Pathname.new('.')).to_s
end
end
end
end
end