From 9f6fab823290c00130b8cd5e3a4968bec65381bf Mon Sep 17 00:00:00 2001 From: Tomasz Gieniusz Date: Sat, 13 Oct 2012 17:20:06 +0200 Subject: [PATCH] git_command_observer --- lib/git_stats/cli.rb | 4 +++- lib/git_stats/generator.rb | 7 ++++++- lib/git_stats/git_data/command.rb | 3 +++ lib/git_stats/git_data/repo.rb | 11 ++++++++--- 4 files changed, 20 insertions(+), 5 deletions(-) diff --git a/lib/git_stats/cli.rb b/lib/git_stats/cli.rb index db8916988..af2a54afb 100644 --- a/lib/git_stats/cli.rb +++ b/lib/git_stats/cli.rb @@ -6,7 +6,9 @@ class GitStats::CLI raise "Wrong number of arguments\nUsage: git_stats repo_path output_path" unless args.size == 2 repo_path, out_path = args - GitStats::Generator.new(repo_path, out_path).generate + GitStats::Generator.new(repo_path, out_path) { |g| + g.git_command_observer { |command| puts command } + }.generate end end diff --git a/lib/git_stats/generator.rb b/lib/git_stats/generator.rb index 1ac363e4e..338815c49 100644 --- a/lib/git_stats/generator.rb +++ b/lib/git_stats/generator.rb @@ -2,12 +2,17 @@ module GitStats class Generator def initialize(repo_path, out_path) @repo_path, @out_path = repo_path, out_path + yield self if block_given? + end + + def git_command_observer(&block) + @git_command_observer = block end def generate validate_paths - repo = GitData::Repo.new(@repo_path) + repo = GitData::Repo.new(path: @repo_path, git_command_observer: @git_command_observer) view_data = StatsView::ViewData.new(repo) view = StatsView::View.new(view_data, @out_path) diff --git a/lib/git_stats/git_data/command.rb b/lib/git_stats/git_data/command.rb index 3a1e49c73..40f6c0f22 100644 --- a/lib/git_stats/git_data/command.rb +++ b/lib/git_stats/git_data/command.rb @@ -1,12 +1,15 @@ module GitStats module GitData class Command + attr_reader :repo, :command + def initialize(repo, command) @repo = repo @command = command end def run + repo.git_command_observer.try(:call, @command) in_repo { %x[#@command] } end diff --git a/lib/git_stats/git_data/repo.rb b/lib/git_stats/git_data/repo.rb index 3cdc168bd..27d72e176 100644 --- a/lib/git_stats/git_data/repo.rb +++ b/lib/git_stats/git_data/repo.rb @@ -1,10 +1,15 @@ +require 'git_stats/hash_initializable' + module GitStats module GitData class Repo - attr_reader :path + include HashInitializable - def initialize(path) - @path = File.expand_path(path) + attr_reader :path, :git_command_observer + + def initialize(params) + super(params) + @path = File.expand_path(@path) end def authors