Sha256: 5f5b8db819c7c569a8f95d3c948b90f1ec0ea09314e5b1152ef8e28a9093fa78

Contents?: true

Size: 996 Bytes

Versions: 1

Compression:

Stored size: 996 Bytes

Contents

require_relative 'inspector'

module GitStats
  class Generator
    include GitStats::Inspector

    delegate :add_command_observer, to: :@repo
    delegate :render_all, to: :@view

    attr_reader :path, :out_path

    def initialize(options)
      @path = validate_repo_path(options[:path])
      @out_path = File.expand_path(options[:out_path])

      @repo = GitData::Repo.new(options.merge(path: path))
      view_data = StatsView::ViewData.new(@repo)
      @view = StatsView::View.new(view_data, out_path)

      yield self if block_given?
    end

    private

    def validate_repo_path(repo_path)
      raise ArgumentError, '`path` is not specified' unless repo_path

      path = File.expand_path(repo_path)
      raise ArgumentError, "'#{path}' is not a git repository" unless valid_repo_path?(path)

      path
    end

    def valid_repo_path?(repo_path)
      Dir.exist?("#{repo_path}/.git") || File.exist?("#{repo_path}/.git") || File.exist?("#{repo_path}/HEAD")
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
nova_git_stats-2.2.0 lib/git_stats/generator.rb