Sha256: 70183f05b3f62335b4bd015c931da9cb2799ee26b40251177902bf1040b2eb1e

Contents?: true

Size: 1.3 KB

Versions: 7

Compression:

Stored size: 1.3 KB

Contents

# 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)
          subclasses.each do |klass|
            return klass.new(line) if klass.match?(line)
          end
          UnrecognizedLine.new(line)
        end

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

        def initialize(line)
          @line = line
        end

        def to_s
          @line
        end

        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)
          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
      end
    end
  end
end

require_relative 'empty'
require_relative 'comment'
require_relative 'pattern'
require_relative 'unrecognized_line'

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
codeowners-checker-1.1.2 lib/codeowners/checker/group/line.rb
codeowners-checker-1.1.1 lib/codeowners/checker/group/line.rb
codeowners-checker-1.0.5 lib/codeowners/checker/group/line.rb
codeowners-checker-1.0.4 lib/codeowners/checker/group/line.rb
codeowners-checker-1.0.3 lib/codeowners/checker/group/line.rb
codeowners-checker-1.0.2 lib/codeowners/checker/group/line.rb
codeowners-checker-1.0.1 lib/codeowners/checker/group/line.rb