Sha256: b63f5e6df7f293d423fcc27e2fc99c2fde3bc6a9b22f3d7585c5b089e303bc5b

Contents?: true

Size: 889 Bytes

Versions: 3

Compression:

Stored size: 889 Bytes

Contents

# frozen_string_literal: true

require "codeowners/git"

module Codeowners
  class ListContributors
    class Result < ::Codeowners::Result
      def initialize(file = nil, contributors = [])
        @file = file
        @contributors = contributors
      end

      def successful?
        !@file.nil?
      end

      def to_s
        [@file, "", *@contributors.map(&:to_s)].join("\n")
      end

      def to_a
        @contributors.dup
      end

      def to_csv
        @contributors.map(&:to_csv).join("\n")
      end
    end

    def initialize(base_directory, git: Git.new(base_directory))
      @git = git
    end

    def call(file, debug = false)
      contributors = @git.contributors(file, debug)
      return Result.new if contributors.empty?

      contributors = contributors.each.lazy.sort_by { |c| -c.insertions }

      Result.new(file, contributors)
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
codeowners-0.0.5 lib/codeowners/list_contributors.rb
codeowners-0.0.4 lib/codeowners/list_contributors.rb
codeowners-0.0.3 lib/codeowners/list_contributors.rb