diff options
author | Carl Lerche <carllerche@mac.com> | 2010-02-02 15:11:25 -0800 |
---|---|---|
committer | Carl Lerche <carllerche@mac.com> | 2010-02-02 15:11:25 -0800 |
commit | ea0889597a461d3954baccd4aaf50c09ce397fc2 (patch) | |
tree | 592241ec2dcad2b9c408a11a412bf4a7ddfe1518 | |
parent | f8419d860688e6d32faa4f763761b7145e8f3765 (diff) | |
download | bundler-ea0889597a461d3954baccd4aaf50c09ce397fc2.tar.gz |
Add the ability to specify a location with bundle install
-rw-r--r-- | bundler.gemspec | 2 | ||||
-rw-r--r-- | lib/bundler.rb | 21 | ||||
-rw-r--r-- | lib/bundler/cli.rb | 4 | ||||
-rw-r--r-- | lib/bundler/settings.rb | 29 | ||||
-rw-r--r-- | spec/install/gems_spec.rb | 9 | ||||
-rw-r--r-- | spec/support/helpers.rb | 3 |
6 files changed, 50 insertions, 18 deletions
diff --git a/bundler.gemspec b/bundler.gemspec index e858e3a06e..4ea647a52a 100644 --- a/bundler.gemspec +++ b/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} diff --git a/lib/bundler.rb b/lib/bundler.rb index 17307cae1a..200c8d9c0d 100644 --- a/lib/bundler.rb +++ b/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 @@ module Bundler def configure @configured ||= begin - point_gem_home(env[:bundle_path]) + point_gem_home(settings[:path]) true end end @@ -49,7 +50,7 @@ module Bundler 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 @@ module Bundler default_gemfile.dirname end + def settings + @settings ||= Settings.new(root) + end + private def default_gemfile @@ -103,18 +108,6 @@ module Bundler 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) diff --git a/lib/bundler/cli.rb b/lib/bundler/cli.rb index 959735ff84..d2aa92a902 100644 --- a/lib/bundler/cli.rb +++ b/lib/bundler/cli.rb @@ -48,11 +48,13 @@ module Bundler 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 diff --git a/lib/bundler/settings.rb b/lib/bundler/settings.rb new file mode 100644 index 0000000000..9af7ba8bdd --- /dev/null +++ b/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
\ No newline at end of file diff --git a/spec/install/gems_spec.rb b/spec/install/gems_spec.rb index 38cc8dbd5f..6d8fe8a182 100644 --- a/spec/install/gems_spec.rb +++ b/spec/install/gems_spec.rb @@ -186,7 +186,7 @@ describe "gemfile install with gem sources" do 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 @@ describe "gemfile install with gem sources" do 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 diff --git a/spec/support/helpers.rb b/spec/support/helpers.rb index b9089bbe09..4f78173190 100644 --- a/spec/support/helpers.rb +++ b/spec/support/helpers.rb @@ -51,8 +51,9 @@ module Spec 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 |