mirror of
https://github.com/tomgi/git_stats.git
synced 2025-01-03 11:12:11 +01:00
will create output directory if doesn't exist
This commit is contained in:
parent
4807e11353
commit
b5f198a240
3 changed files with 7 additions and 13 deletions
|
@ -5,7 +5,7 @@ module GitStats
|
||||||
delegate :render_all, to: :@view
|
delegate :render_all, to: :@view
|
||||||
|
|
||||||
def initialize(repo_path, out_path)
|
def initialize(repo_path, out_path)
|
||||||
validate_paths(repo_path, out_path)
|
validate_repo_path(repo_path)
|
||||||
|
|
||||||
@repo = GitData::Repo.new(path: repo_path)
|
@repo = GitData::Repo.new(path: repo_path)
|
||||||
view_data = StatsView::ViewData.new(@repo)
|
view_data = StatsView::ViewData.new(@repo)
|
||||||
|
@ -15,18 +15,12 @@ module GitStats
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
def validate_paths(repo_path, out_path)
|
|
||||||
validate_repo_path(repo_path)
|
|
||||||
validate_out_path(out_path)
|
|
||||||
end
|
|
||||||
|
|
||||||
def validate_repo_path(repo_path)
|
def validate_repo_path(repo_path)
|
||||||
raise ArgumentError, "#{repo_path} is not a git repository" unless Dir.exists?("#{repo_path}/.git")
|
raise ArgumentError, "#{repo_path} is not a git repository" unless Dir.exists?("#{repo_path}/.git")
|
||||||
end
|
end
|
||||||
|
|
||||||
def validate_out_path(out_path)
|
|
||||||
raise ArgumentError, "#{out_path} is not a directory" unless Dir.exists?(out_path)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -60,9 +60,14 @@ module GitStats
|
||||||
end
|
end
|
||||||
|
|
||||||
def prepare_static_content
|
def prepare_static_content
|
||||||
|
create_out_dir
|
||||||
FileUtils.cp_r(Dir["../../../../templates/static/*".absolute_path], @out_path)
|
FileUtils.cp_r(Dir["../../../../templates/static/*".absolute_path], @out_path)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def create_out_dir
|
||||||
|
FileUtils.mkdir_p(@out_path) unless Dir.exists?(@out_path)
|
||||||
|
end
|
||||||
|
|
||||||
def prepare_assets
|
def prepare_assets
|
||||||
FileUtils.cp_r('../../../../templates/assets'.absolute_path, @out_path)
|
FileUtils.cp_r('../../../../templates/assets'.absolute_path, @out_path)
|
||||||
end
|
end
|
||||||
|
|
|
@ -13,11 +13,6 @@ describe GitStats::Generator do
|
||||||
expect { generator }.to raise_error(ArgumentError)
|
expect { generator }.to raise_error(ArgumentError)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should raise exception if given out directory doesn't exist" do
|
|
||||||
Dir.should_receive(:exists?).with(out_path).and_return(false)
|
|
||||||
expect { generator }.to raise_error(ArgumentError)
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'should pass command observer to repo' do
|
it 'should pass command observer to repo' do
|
||||||
repo = double('repo')
|
repo = double('repo')
|
||||||
GitStats::GitData::Repo.should_receive(:new).with(path: repo_path).and_return(repo)
|
GitStats::GitData::Repo.should_receive(:new).with(path: repo_path).and_return(repo)
|
||||||
|
|
Loading…
Reference in a new issue