summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarl Lerche <carllerche@mac.com>2010-02-01 07:11:37 -0800
committerCarl Lerche <carllerche@mac.com>2010-02-01 07:11:37 -0800
commitbc310f716c37c6c592141808aed223d806ad1850 (patch)
tree0d764e488b2a82e31e8d69763215aca3368db74b
parentde65328a3f4edba97ac187765886c0cd1a268fff (diff)
downloadbundler-bc310f716c37c6c592141808aed223d806ad1850.tar.gz
First pass at being able to set the bundle install path.
-rw-r--r--bundler.gemspec2
-rw-r--r--lib/bundler.rb101
-rw-r--r--spec/install/gems_spec.rb31
-rw-r--r--spec/spec_helper.rb7
4 files changed, 95 insertions, 46 deletions
diff --git a/bundler.gemspec b/bundler.gemspec
index 40b4942a9c..6954f734f1 100644
--- a/bundler.gemspec
+++ b/bundler.gemspec
@@ -6,7 +6,7 @@ Gem::Specification.new do |s|
s.required_rubygems_version = Gem::Requirement.new(">= 1.3.5") if s.respond_to? :required_rubygems_version=
s.authors = ["Carl Lerche", "Yehuda Katz"]
- s.date = %q{2010-01-31}
+ s.date = %q{2010-02-01}
s.default_executable = %q{bundle}
s.email = ["carlhuda@engineyard.com"]
s.executables = ["bundle"]
diff --git a/lib/bundler.rb b/lib/bundler.rb
index 6c5537c62a..eae1114ed1 100644
--- a/lib/bundler.rb
+++ b/lib/bundler.rb
@@ -23,62 +23,77 @@ module Bundler
class VersionConflict < StandardError; end
class GemfileError < StandardError; end
- def self.ui
- @ui ||= UI.new
- end
+ class << self
+ attr_accessor :ui, :bundle_path
+
+ def configure
+ @configured ||= begin
+ self.bundle_path = Pathname.new(ENV['BUNDLE_PATH'] || Gem.dir)
+ point_gem_home(ENV['BUNDLE_PATH'])
+ true
+ end
+ end
- def self.ui=(ui)
- @ui = ui
- end
+ def ui
+ @ui ||= UI.new
+ end
- def self.setup(*groups)
- gemfile = default_gemfile
- load(gemfile).setup(*groups)
- end
+ def setup(*groups)
+ gemfile = default_gemfile
+ load(gemfile).setup(*groups)
+ end
- def self.load(gemfile = default_gemfile)
- root = Pathname.new(gemfile).dirname
- Environment.new root, definition(gemfile)
- end
+ def load(gemfile = default_gemfile)
+ root = Pathname.new(gemfile).dirname
+ Environment.new root, definition(gemfile)
+ end
- def self.definition(gemfile = default_gemfile)
- root = Pathname.new(gemfile).dirname
- lockfile = root.join("vendor/lock.yml")
- if lockfile.exist?
- Definition.from_lock(lockfile)
- else
- Definition.from_gemfile(gemfile)
+ def definition(gemfile = default_gemfile)
+ configure
+ root = Pathname.new(gemfile).dirname
+ lockfile = root.join("vendor/lock.yml")
+ if lockfile.exist?
+ Definition.from_lock(lockfile)
+ else
+ Definition.from_gemfile(gemfile)
+ end
end
- end
- def self.home
- Pathname.new(Gem.dir).join("bundler")
- end
+ def home
+ Pathname.new(bundle_path).join("bundler")
+ end
- def self.install_path
- home.join("gems")
- end
+ def install_path
+ home.join("gems")
+ end
- def self.cache
- home.join("cache")
- end
+ def cache
+ home.join("cache")
+ end
- def self.root
- default_gemfile.dirname
- end
+ def root
+ default_gemfile.dirname
+ end
+
+ private
-private
+ def default_gemfile
+ current = Pathname.new(Dir.pwd)
- def self.default_gemfile
- current = Pathname.new(Dir.pwd)
+ until current.root?
+ filename = current.join("Gemfile")
+ return filename if filename.exist?
+ current = current.parent
+ end
- until current.root?
- filename = current.join("Gemfile")
- return filename if filename.exist?
- current = current.parent
+ raise GemfileNotFound, "The default Gemfile was not found"
end
- raise GemfileNotFound, "The default Gemfile was not found"
+ def point_gem_home(path)
+ return unless path
+ ENV['GEM_HOME'] = File.expand_path(path, root)
+ ENV['GEM_PATH'] = ''
+ Gem.clear_paths
+ end
end
-
end \ No newline at end of file
diff --git a/spec/install/gems_spec.rb b/spec/install/gems_spec.rb
index 55a298d150..a58fcd1512 100644
--- a/spec/install/gems_spec.rb
+++ b/spec/install/gems_spec.rb
@@ -163,7 +163,38 @@ describe "gemfile install with gem sources" do
should_be_installed "rack 1.0.0"
end
end
+ end
+
+ describe "with BUNDLE_PATH set" do
+ before :each do
+ build_lib "rack", "1.0.0", :to_system => true do |s|
+ s.write "lib/rack.rb", "raise 'FAIL'"
+ end
+
+ gemfile <<-G
+ source "file://#{gem_repo1}"
+ gem "rack"
+ G
+ end
+
+ it "installs gems to BUNDLE_PATH" do
+ ENV['BUNDLE_PATH'] = bundled_app('vendor').to_s
+ bundle :install
+
+ bundled_app('vendor/gems/rack-1.0.0').should be_directory
+ should_be_installed "rack 1.0.0"
+ end
+
+ it "installs gems to BUNDLE_PATH from .bundleconfig" do
+ pending
+ config "BUNDLE_PATH" => bundled_app("vendor").to_s
+
+ bundle :install
+
+ bundled_app('vendor/gems/rack-1.0.0').should be_directory
+ should_be_installed "rack 1.0.0"
+ end
end
describe "when packed and locked" do
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
index 3ecffc836d..776c8d8ec3 100644
--- a/spec/spec_helper.rb
+++ b/spec/spec_helper.rb
@@ -39,7 +39,10 @@ Spec::Runner.configure do |config|
config.after :each do
Gem.platforms = nil
Dir.chdir(original_wd)
- ENV['GEM_HOME'] = ENV['GEM_PATH'] = original_gem_home
- ENV['PATH'] = original_path
+ # Reset ENV
+ ENV['GEM_HOME'] = original_gem_home
+ ENV['GEM_PATH'] = original_gem_home
+ ENV['BUNDLE_PATH'] = nil
+ ENV['PATH'] = original_path
end
end \ No newline at end of file