Sha256: 1098147175afd2197b97ed94db25c555677822785eded7d10150dc602e4bf7eb

Contents?: true

Size: 896 Bytes

Versions: 1

Compression:

Stored size: 896 Bytes

Contents

# frozen_string_literal: true

require_relative 'line'

module Codeowners
  class Checker
    class Group
      # Defines and manages line type pattern.
      class Pattern < Line
        attr_accessor :pattern, :owners

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

        def initialize(line)
          super
          parse(line)
        end

        def owner
          owners.first
        end

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

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

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

        private

        def regex
          Regexp.new(pattern.gsub(%r{/\*\*}, '(/[^/]+)+').gsub(/\*/, '[^/]+'))
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
codeowners-checker-1.0.0 lib/codeowners/checker/group/pattern.rb