lib/sandbox/installer.rb in ruby-virtualenv-0.5.0 vs lib/sandbox/installer.rb in ruby-virtualenv-0.5.1
- old
+ new
@@ -45,131 +45,105 @@
def create_directories
gembin = File.join(target, 'rubygems', 'bin')
FileUtils.mkdir_p(gembin)
bin = File.join(target, 'bin')
- FileUtils.ln_s( gembin, bin )
+ FileUtils.ln_s(gembin, bin)
end
def install_gemrc
filename = File.join(target, '.gemrc')
- template = File.read(File.dirname( __FILE__ ) + '/templates/gemrc.erb')
- script = ERB.new(template)
- output = script.result(binding)
-
- File.open(filename, 'w') do |f|
- f.write output
- end
+ template = File.read(File.dirname(__FILE__) + '/templates/gemrc.erb')
+ output = ERB.new(template).result(binding)
+ File.open(filename, 'w') { |f| f.write(output) }
end
def install_scripts
filename = File.join(target, 'bin', 'activate')
- template = File.read(File.dirname( __FILE__ ) + '/templates/activate.erb')
- script = ERB.new(template)
- output = script.result(binding)
-
- File.open(filename, 'w') do |f|
- f.write output
- end
+ template = File.read(File.dirname(__FILE__) + '/templates/activate.erb')
+ output = ERB.new(template).result(binding)
+ File.open(filename, 'w') { |f| f.write(output) }
end
def install_gems
- # gem = `which gem`.chomp
- # return if gem.empty?
- gems = options[ :gems ] || []
+ gems = options[:gems] || []
if gems.size == 0
- tell( " nothing to install" )
+ tell(" nothing to install")
return
end
-
+
begin
setup_sandbox_env
gems.each do |gem|
- tell_unless_really_quiet( " gem: #{gem}" )
+ tell_unless_really_quiet(" gem: #{gem}")
cmd = "gem install #{gem}"
- # cmd = cmd + ' -V' if Sandbox.really_verbose?
- status, output = shell_out( cmd )
+ status, output = shell_out(cmd)
unless status
- tell_unless_really_quiet( " failed to install gem: #{gem}" )
+ tell_unless_really_quiet(" failed to install gem: #{gem}")
end
end
ensure
restore_sandbox_env
end
end
-
- def shell_out( cmd )
- # err_capture = Sandbox.really_verbose? '2>&1' : '2>/dev/null'
- # out = `#{cmd} #{err_capture}`
+
+ def shell_out(cmd)
out = `#{cmd} 2>/dev/null`
result = $?.exitstatus == 0
- [ result, out ]
+ [result, out]
end
-
+
def setup_sandbox_env
- @old_env = Hash[ *ENV.select { |k,v| ['HOME','GEM_HOME','GEM_PATH'].include?( k ) }.flatten ]
- # @old_env = {}
- # @old_env[ 'HOME' ] = ENV[ 'HOME' ]
- # @old_env[ 'GEM_HOME' ] = ENV[ 'GEM_HOME' ]
- # @old_env[ 'GEM_PATH' ] = ENV[ 'GEM_PATH' ]
-
- ENV[ 'HOME' ] = target
- ENV[ 'GEM_HOME' ] = "#{target}/rubygems"
- ENV[ 'GEM_PATH' ] = "#{target}/rubygems"
+ @old_env = Hash[ *ENV.select { |k,v| ['HOME','GEM_HOME','GEM_PATH'].include?(k) }.flatten ]
+
+ ENV['HOME'] = target
+ ENV['GEM_HOME'] = "#{target}/rubygems"
+ ENV['GEM_PATH'] = "#{target}/rubygems"
end
-
+
def restore_sandbox_env
- # ENV.update( @old_env )
- ENV[ 'HOME' ] = @old_env[ 'HOME' ]
- ENV[ 'GEM_HOME' ] = @old_env[ 'GEM_HOME' ]
- ENV[ 'GEM_PATH' ] = @old_env[ 'GEM_PATH' ]
+ ENV['HOME'] = @old_env['HOME']
+ ENV['GEM_HOME'] = @old_env['GEM_HOME']
+ ENV['GEM_PATH'] = @old_env['GEM_PATH']
end
-
- def resolve_target( path )
- # should consider replacing with 'pathname' => Pathname.new( path )
- path = fix_path( path )
- if File.exists?( path )
+
+ def resolve_target(path)
+ path = fix_path(path)
+ if File.exists?(path)
raise Sandbox::Error, "target '#{path}' exists"
end
-
+
base = path
- while base = File.dirname( base )
- if check_path!( base )
+ while base = File.dirname(base)
+ if check_path!(base)
break
elsif base == '/'
raise "something is seriously wrong; we should never get here"
end
end
- return path
+
+ path
end
-
- def check_path!( path )
- if File.directory?( path )
- if File.writable?( path )
+
+ def check_path!(path)
+ if File.directory?(path)
+ if File.writable?(path)
return true
else
raise Sandbox::Error, "path '#{path}' has a permission problem"
end
- elsif File.exists?( path )
+ elsif File.exists?(path)
raise Sandbox::Error, "path '#{path}' is not a directory"
end
false
end
-
- def fix_path( path )
- unless path.index( '/' ) == 0
- path = File.join( FileUtils.pwd, path )
+
+ def fix_path(path)
+ unless path.index('/') == 0
+ path = File.join(FileUtils.pwd, path)
end
path
end
- ## END PUBLIC INSTANCE METHODS
-
-
- ## PRIVATE INSTANCE METHODS
- private
-
- ## END PRIVATE INSTANCE METHODS
-
end
-
-end
\ No newline at end of file
+
+end