Sha256: 7adab00984210d11122756620b6c2e1458fe59b2985304ee16e77ae3d6400137

Contents?: true

Size: 750 Bytes

Versions: 2

Compression:

Stored size: 750 Bytes

Contents

module Owners
  # Parses an OWNERS file and returns an array of owners
  # that have subscribed to a specified file path.
  #
  # @api private
  class Config
    def initialize(file)
      @config = file.read
      @root = file.dirname.to_s
    end

    def owners(path)
      if path.start_with?(@root)
        relative = path.sub("#{@root}/", "")

        search do |subscription, results|
          owner, pattern = subscription.split(/\s+/, 2)
          regex = Regexp.new(pattern || ".*")
          results << owner if regex =~ relative
        end
      end
    end

    private

    def search(&block)
      subscriptions.each_with_object([], &block)
    end

    def subscriptions
      @config.split("\n").reject(&:empty?)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
owners-0.0.2 lib/owners/config.rb
owners-0.0.1 lib/owners/config.rb