Permalink
Browse files

Add the ability to specify a location with bundle install

  • Loading branch information...
1 parent f8419d8 commit ea0889597a461d3954baccd4aaf50c09ce397fc2 Carl Lerche committed Feb 2, 2010
Showing with 50 additions and 18 deletions.
  1. +1 −1 bundler.gemspec
  2. +7 −14 lib/bundler.rb
  3. +3 −1 lib/bundler/cli.rb
  4. +29 −0 lib/bundler/settings.rb
  5. +8 −1 spec/install/gems_spec.rb
  6. +2 −1 spec/support/helpers.rb
View
2 bundler.gemspec
@@ -10,7 +10,7 @@ Gem::Specification.new do |s|
s.default_executable = %q{bundle}
s.email = ["carlhuda@engineyard.com"]
s.executables = ["bundle"]
- s.files = ["bin/bundle", "lib/bundler", "lib/bundler/cli.rb", "lib/bundler/definition.rb", "lib/bundler/dependency.rb", "lib/bundler/dsl.rb", "lib/bundler/environment.rb", "lib/bundler/index.rb", "lib/bundler/installer.rb", "lib/bundler/remote_specification.rb", "lib/bundler/resolver.rb", "lib/bundler/rubygems.rb", "lib/bundler/setup.rb", "lib/bundler/source.rb", "lib/bundler/specification.rb", "lib/bundler/templates", "lib/bundler/templates/environment.erb", "lib/bundler/templates/Gemfile", "lib/bundler/ui.rb", "lib/bundler/vendor", "lib/bundler/vendor/thor", "lib/bundler/vendor/thor/actions", "lib/bundler/vendor/thor/actions/create_file.rb", "lib/bundler/vendor/thor/actions/directory.rb", "lib/bundler/vendor/thor/actions/empty_directory.rb", "lib/bundler/vendor/thor/actions/file_manipulation.rb", "lib/bundler/vendor/thor/actions/inject_into_file.rb", "lib/bundler/vendor/thor/actions.rb", "lib/bundler/vendor/thor/base.rb", "lib/bundler/vendor/thor/core_ext", "lib/bundler/vendor/thor/core_ext/file_binary_read.rb", "lib/bundler/vendor/thor/core_ext/hash_with_indifferent_access.rb", "lib/bundler/vendor/thor/core_ext/ordered_hash.rb", "lib/bundler/vendor/thor/error.rb", "lib/bundler/vendor/thor/group.rb", "lib/bundler/vendor/thor/invocation.rb", "lib/bundler/vendor/thor/parser", "lib/bundler/vendor/thor/parser/argument.rb", "lib/bundler/vendor/thor/parser/arguments.rb", "lib/bundler/vendor/thor/parser/option.rb", "lib/bundler/vendor/thor/parser/options.rb", "lib/bundler/vendor/thor/parser.rb", "lib/bundler/vendor/thor/rake_compat.rb", "lib/bundler/vendor/thor/runner.rb", "lib/bundler/vendor/thor/shell", "lib/bundler/vendor/thor/shell/basic.rb", "lib/bundler/vendor/thor/shell/color.rb", "lib/bundler/vendor/thor/shell.rb", "lib/bundler/vendor/thor/task.rb", "lib/bundler/vendor/thor/util.rb", "lib/bundler/vendor/thor/version.rb", "lib/bundler/vendor/thor.rb", "lib/bundler.rb", "LICENSE", "README.markdown"]
+ s.files = ["bin/bundle", "lib/bundler", "lib/bundler/cli.rb", "lib/bundler/definition.rb", "lib/bundler/dependency.rb", "lib/bundler/dsl.rb", "lib/bundler/environment.rb", "lib/bundler/index.rb", "lib/bundler/installer.rb", "lib/bundler/remote_specification.rb", "lib/bundler/resolver.rb", "lib/bundler/rubygems.rb", "lib/bundler/settings.rb", "lib/bundler/setup.rb", "lib/bundler/source.rb", "lib/bundler/specification.rb", "lib/bundler/templates", "lib/bundler/templates/environment.erb", "lib/bundler/templates/Gemfile", "lib/bundler/ui.rb", "lib/bundler/vendor", "lib/bundler/vendor/thor", "lib/bundler/vendor/thor/actions", "lib/bundler/vendor/thor/actions/create_file.rb", "lib/bundler/vendor/thor/actions/directory.rb", "lib/bundler/vendor/thor/actions/empty_directory.rb", "lib/bundler/vendor/thor/actions/file_manipulation.rb", "lib/bundler/vendor/thor/actions/inject_into_file.rb", "lib/bundler/vendor/thor/actions.rb", "lib/bundler/vendor/thor/base.rb", "lib/bundler/vendor/thor/core_ext", "lib/bundler/vendor/thor/core_ext/file_binary_read.rb", "lib/bundler/vendor/thor/core_ext/hash_with_indifferent_access.rb", "lib/bundler/vendor/thor/core_ext/ordered_hash.rb", "lib/bundler/vendor/thor/error.rb", "lib/bundler/vendor/thor/group.rb", "lib/bundler/vendor/thor/invocation.rb", "lib/bundler/vendor/thor/parser", "lib/bundler/vendor/thor/parser/argument.rb", "lib/bundler/vendor/thor/parser/arguments.rb", "lib/bundler/vendor/thor/parser/option.rb", "lib/bundler/vendor/thor/parser/options.rb", "lib/bundler/vendor/thor/parser.rb", "lib/bundler/vendor/thor/rake_compat.rb", "lib/bundler/vendor/thor/runner.rb", "lib/bundler/vendor/thor/shell", "lib/bundler/vendor/thor/shell/basic.rb", "lib/bundler/vendor/thor/shell/color.rb", "lib/bundler/vendor/thor/shell.rb", "lib/bundler/vendor/thor/task.rb", "lib/bundler/vendor/thor/util.rb", "lib/bundler/vendor/thor/version.rb", "lib/bundler/vendor/thor.rb", "lib/bundler.rb", "LICENSE", "README.markdown"]
s.homepage = %q{http://github.com/carlhuda/bundler}
s.require_paths = ["lib"]
s.rubygems_version = %q{1.3.5}
View
21 lib/bundler.rb
@@ -14,6 +14,7 @@ module Bundler
autoload :Installer, 'bundler/installer'
autoload :RemoteSpecification, 'bundler/remote_specification'
autoload :Resolver, 'bundler/resolver'
+ autoload :Settings, 'bundler/settings'
autoload :Source, 'bundler/source'
autoload :Specification, 'bundler/specification'
autoload :UI, 'bundler/ui'
@@ -39,7 +40,7 @@ class << self
def configure
@configured ||= begin
- point_gem_home(env[:bundle_path])
+ point_gem_home(settings[:path])
true
end
end
@@ -49,7 +50,7 @@ def ui
end
def bundle_path
- @bundle_path ||= Pathname.new(env[:bundle_path] || Gem.dir).expand_path(root)
+ @bundle_path ||= Pathname.new(settings[:path] || Gem.dir).expand_path(root)
end
def setup(*groups)
@@ -89,6 +90,10 @@ def root
default_gemfile.dirname
end
+ def settings
+ @settings ||= Settings.new(root)
+ end
+
private
def default_gemfile
@@ -103,18 +108,6 @@ def default_gemfile
raise GemfileNotFound, "The default Gemfile was not found"
end
- def env
- @env ||= begin
- env = {}
- file = "#{root}/.bundleconfig"
- config = File.exist?(file) ? YAML.load_file(file) : {}
- %w(BUNDLE_PATH).each do |key|
- env[key.downcase.to_sym] = config[key] || ENV[key]
- end
- env
- end
- end
-
def point_gem_home(path)
return unless path
ENV['GEM_HOME'] = File.expand_path(path, root)
View
4 lib/bundler/cli.rb
@@ -48,11 +48,13 @@ def check
desc "install", "Install the current environment to the system"
method_option :without, :type => :array, :banner => "Exclude gems thar are part of the specified named group"
- def install
+ def install(path = nil)
opts = options.dup
opts[:without] ||= []
opts[:without].map! { |g| g.to_sym }
+ Bundler.settings[:path] = path if path
+
Installer.install(Bundler.root, Bundler.definition, opts)
end
View
29 lib/bundler/settings.rb
@@ -0,0 +1,29 @@
+module Bundler
+ class Settings
+ def initialize(root)
+ @root = root
+ @config = File.exist?(config_file) ? YAML.load_file(config_file) : {}
+ end
+
+ def [](key)
+ key = "BUNDLE_#{key.to_s.upcase}"
+ @config[key] || ENV[key]
+ end
+
+ def []=(key, value)
+ key = "BUNDLE_#{key.to_s.upcase}"
+ @config[key] = value
+ FileUtils.mkdir_p(config_file.dirname)
+ File.open(config_file, 'w') do |f|
+ f.puts @config.to_yaml
+ end
+ value
+ end
+
+ private
+
+ def config_file
+ Pathname.new("#{@root}/.bundle/config")
+ end
+ end
+end
View
9 spec/install/gems_spec.rb
@@ -186,7 +186,7 @@
should_be_installed "rack 1.0.0"
end
- it "installs gems to BUNDLE_PATH from .bundleconfig" do
+ it "installs gems to BUNDLE_PATH from .bundle/config" do
config "BUNDLE_PATH" => bundled_app("vendor").to_s
bundle :install
@@ -206,6 +206,13 @@
bundled_app('vendor/gems/rack-1.0.0').should be_directory
should_be_installed "rack 1.0.0"
end
+
+ it "sets BUNDLE_PATH as the first argument to bundle install" do
+ bundle "install ./vendor"
+
+ 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
View
3 spec/support/helpers.rb
@@ -51,8 +51,9 @@ def ruby(opts, ruby = nil)
end
def config(config = nil)
- path = bundled_app('.bundleconfig')
+ path = bundled_app('.bundle/config')
return YAML.load_file(path) unless config
+ FileUtils.mkdir_p(File.dirname(path))
File.open(path, 'w') do |f|
f.puts config.to_yaml
end

0 comments on commit ea08895

Please sign in to comment.