Sha256: dffa70d938740d38f715acdd56cabd8e47254f1df7da018eeacf2773f41302dc

Contents?: true

Size: 1 KB

Versions: 4

Compression:

Stored size: 1 KB

Contents

# frozen_string_literal: true

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

4 entries across 4 versions & 1 rubygems

Version Path
nova_git_stats-2.4.2 lib/git_stats/generator.rb
nova_git_stats-2.4.1 lib/git_stats/generator.rb
nova_git_stats-2.4.0 lib/git_stats/generator.rb
nova_git_stats-2.3.0 lib/git_stats/generator.rb