Skip to content
Browse files

creation of the project checkout directory based on env variable (wit…

…h a default of ~/.goldberg)
  • Loading branch information...
1 parent f742e70 commit a17d43e7bf1eea11305f2b2390b444c76d10204a @srushti srushti committed
Showing with 41 additions and 2 deletions.
  1. +3 −0 .rdebugrc
  2. +21 −2 lib/goldberg/paths.rb
  3. +17 −0 spec/goldberg/paths_spec.rb
View
3 .rdebugrc
@@ -0,0 +1,3 @@
+set autolist
+set autoeval
+set autoreload
View
23 lib/goldberg/paths.rb
@@ -1,3 +1,5 @@
+require "fileutils"
+
module Goldberg
module Paths
class << self
@@ -10,8 +12,25 @@ def absolute_path(*args)
end
def projects
- absolute_path("projects")
+ goldberg_path = Env['GOLDBERG_PATH'] || File.join(Env['HOME'], '.goldberg')
+ create_if_doesnt_exist(File.join(goldberg_path, 'projects'))
+ end
+
+ def create_if_doesnt_exist(path)
+ path.tap{|path| FileUtils.mkdir_p(path) if !File.exist?(path)}
end
end
end
-end
+end
+
+module Env
+ class << self
+ def [](variable_name)
+ ENV[variable_name]
+ end
+
+ def home
+ ["HOME"]
+ end
+ end
+end
View
17 spec/goldberg/paths_spec.rb
@@ -0,0 +1,17 @@
+require "spec_helper"
+
+describe Goldberg::Paths do
+ it "creates the goldberg path if it doesn't exist and returns it" do
+ File.stub!(:exist?).and_return(true)
+ Env.should_receive(:[]).with('GOLDBERG_PATH').and_return(nil)
+ Env.should_receive(:[]).with('HOME').and_return("path_to_home")
+ Goldberg::Paths.projects.should == 'path_to_home/.goldberg/projects'
+ end
+
+ it "creates the goldberg path using the environment variable if defined" do
+ File.stub!(:exist?).and_return(true)
+ Env.should_receive(:[]).with('GOLDBERG_PATH').and_return('overridden_goldberg_path')
+ Goldberg::Paths.projects.should == 'overridden_goldberg_path/projects'
+ end
+end
+

0 comments on commit a17d43e

Please sign in to comment.
Something went wrong with that request. Please try again.