diff options
author | Carl Lerche <carllerche@mac.com> | 2009-07-23 12:23:30 -0700 |
---|---|---|
committer | Carl Lerche <carllerche@mac.com> | 2009-07-23 12:23:30 -0700 |
commit | c4aea86373c8a8d389ebd640fbb6967bed6974d1 (patch) | |
tree | 97482773eedbf357b8892216f967a09797d0d53a | |
parent | f1db45ee4ecccb54e9fabdf2563a1cb521e0694b (diff) | |
download | bundler-c4aea86373c8a8d389ebd640fbb6967bed6974d1.tar.gz |
Allow setting the bindir and the bundle path in the Gemfile
-rw-r--r-- | lib/bundler/cli.rb | 2 | ||||
-rw-r--r-- | lib/bundler/manifest_file.rb | 10 | ||||
-rw-r--r-- | lib/bundler/runtime.rb | 12 | ||||
-rw-r--r-- | spec/bundler/manifest_file_spec.rb | 52 |
4 files changed, 64 insertions, 12 deletions
diff --git a/lib/bundler/cli.rb b/lib/bundler/cli.rb index d79feb3cdb..1d39c97a29 100644 --- a/lib/bundler/cli.rb +++ b/lib/bundler/cli.rb @@ -43,4 +43,4 @@ module Bundler end end end - end +end diff --git a/lib/bundler/manifest_file.rb b/lib/bundler/manifest_file.rb index aa0222fee1..0d97225cf4 100644 --- a/lib/bundler/manifest_file.rb +++ b/lib/bundler/manifest_file.rb @@ -2,7 +2,8 @@ module Bundler class DefaultManifestNotFound < StandardError; end class ManifestFile - attr_reader :sources, :dependencies, :gem_path, :bindir + attr_reader :sources, :dependencies + attr_accessor :gem_path, :bindir def self.load(filename = nil) new(filename).load @@ -32,11 +33,8 @@ module Bundler end def load_manifest - builder = ManifestBuilder.load(self, filename) - Manifest.new(sources, - dependencies, - bindir, - gem_path) + ManifestBuilder.load(self, filename) + Manifest.new(sources, dependencies, bindir, gem_path) end def gem_path diff --git a/lib/bundler/runtime.rb b/lib/bundler/runtime.rb index 265eb2b69f..50706f9052 100644 --- a/lib/bundler/runtime.rb +++ b/lib/bundler/runtime.rb @@ -20,6 +20,18 @@ module Bundler @manifest_file = manifest_file end + def bundle_path(path) + path = Pathname.new(path) + @manifest_file.gem_path = (path.relative? ? + @manifest_file.root.join(path) : path).expand_path + end + + def bin_path(path) + path = Pathname.new(path) + @manifest_file.bindir = (path.relative? ? + @manifest_file.root.join(path) : path).expand_path + end + def source(source) @manifest_file.sources << source end diff --git a/spec/bundler/manifest_file_spec.rb b/spec/bundler/manifest_file_spec.rb index 5b18220e47..752e673106 100644 --- a/spec/bundler/manifest_file_spec.rb +++ b/spec/bundler/manifest_file_spec.rb @@ -11,36 +11,78 @@ describe "Bundler::Manifest" do Dir.chdir(@original_pwd) end + def manifest(*args) + path = args.unshift if args.first.is_a?(Pathname) + str = args.unshift || "" + File.open(path || tmp_file("Gemfile"), 'w') do |f| + f.puts str + end + end + it "finds the default manifest file" do + manifest Dir.chdir(tmp_dir) - FileUtils.touch(tmp_file("Gemfile")) Bundler::ManifestFile.load.filename.should == tmp_file("Gemfile") end it "finds the default manifest file when it's in a parent directory" do + manifest FileUtils.mkdir_p(tmp_file("wot")) - FileUtils.touch(tmp_file("Gemfile")) Dir.chdir(tmp_file("wot")) Bundler::ManifestFile.load.filename.should == tmp_file("Gemfile") end it "sets the default bundle path to vendor/gems" do + manifest Dir.chdir(tmp_dir) - FileUtils.touch(tmp_file("Gemfile")) Bundler::ManifestFile.load.gem_path.should == tmp_file("vendor", "gems") end + it "allows setting the bundle path in the manifest file" do + manifest <<-Gemfile + bundle_path "#{tmp_file('gems')}" + Gemfile + Dir.chdir(tmp_dir) + Bundler::ManifestFile.load.gem_path.should == tmp_file("gems") + end + + it "assumes the bundle_path is relative to the manifest file no matter what the current working dir is" do + manifest <<-Gemfile + bundle_path File.join('..', 'cheezeburgerz') + Gemfile + FileUtils.mkdir_p(tmp_file('w0t')) + Dir.chdir(tmp_file('w0t')) + Bundler::ManifestFile.load.gem_path.should == tmp_file('..', 'cheezeburgerz') + end + it "sets the default bundle path relative to the Gemfile" do + manifest FileUtils.mkdir_p(tmp_file("wot")) - FileUtils.touch(tmp_file("Gemfile")) Dir.chdir(tmp_file("wot")) Bundler::ManifestFile.load.gem_path.should == tmp_file("vendor", "gems") end it "sets the default bindir relative to the Gemfile" do + manifest FileUtils.mkdir_p(tmp_file("wot")) - FileUtils.touch(tmp_file("Gemfile")) Dir.chdir(tmp_file("wot")) Bundler::ManifestFile.load.bindir.should == tmp_file("bin") end + + it "allows setting the bindir in the manifest file" do + manifest <<-Gemfile + bin_path "#{tmp_file('binz')}" + Gemfile + Dir.chdir(tmp_dir) + Bundler::ManifestFile.load.bindir.should == tmp_file('binz') + end + + it "assumes the bindir is relative to the manifest file no matter what the current working dir is" do + manifest <<-Gemfile + bin_path File.join('..', 'cheezeburgerz') + Gemfile + FileUtils.mkdir_p(tmp_file('w0t')) + Dir.chdir(tmp_file('w0t')) + Bundler::ManifestFile.load.bindir.should == tmp_file('..', 'cheezeburgerz') + end end |