mirror of
https://github.com/tomgi/git_stats.git
synced 2024-11-17 17:15:22 +01:00
31 lines
746 B
Ruby
31 lines
746 B
Ruby
# -*- encoding : utf-8 -*-
|
|
module GitStats
|
|
class Generator
|
|
delegate :add_command_observer, to: :@repo
|
|
delegate :render_all, to: :@view
|
|
|
|
def initialize(options)
|
|
validate_repo_path(options[:path])
|
|
|
|
@repo = GitData::Repo.new(options)
|
|
view_data = StatsView::ViewData.new(@repo)
|
|
@view = StatsView::View.new(view_data, options[:out_path])
|
|
|
|
yield self if block_given?
|
|
end
|
|
|
|
private
|
|
|
|
|
|
def validate_repo_path(repo_path)
|
|
raise ArgumentError, "#{repo_path} is not a git repository" unless valid_repo_path?(repo_path)
|
|
end
|
|
|
|
|
|
def valid_repo_path?(repo_path)
|
|
Dir.exists?("#{repo_path}/.git") || File.exists?("#{repo_path}/.git") || File.exists?("#{repo_path}/HEAD")
|
|
end
|
|
|
|
end
|
|
|
|
end
|