diff options
author | Donnie Tognazzini <donnie.tognazzini@appfolio.com> | 2016-01-27 13:37:16 -0800 |
---|---|---|
committer | Donnie Tognazzini <donnie.tognazzini@appfolio.com> | 2016-01-27 14:48:23 -0800 |
commit | 8f8c1c420131acf76089bdeaa50b5c609aa2e71f (patch) | |
tree | d952d200cf5133a80affbf8f0847e32c70423cc2 | |
parent | 505b95d7bde10660134588e1a21668416621fa3d (diff) | |
download | bundler-8f8c1c420131acf76089bdeaa50b5c609aa2e71f.tar.gz |
Forwarding root path to Source::Path from Dsl.
-rw-r--r-- | lib/bundler/dsl.rb | 14 | ||||
-rw-r--r-- | lib/bundler/source/path.rb | 12 | ||||
-rw-r--r-- | spec/bundler/dsl_spec.rb | 1 |
3 files changed, 14 insertions, 13 deletions
diff --git a/lib/bundler/dsl.rb b/lib/bundler/dsl.rb index bc97d9fb62..57be120d9f 100644 --- a/lib/bundler/dsl.rb +++ b/lib/bundler/dsl.rb @@ -49,7 +49,7 @@ module Bundler glob = opts && opts[:glob] name = opts && opts[:name] || "{,*}" development_group = opts && opts[:development_group] || :development - expanded_path = path_relative_to_gemfile(path) + expanded_path = gemfile_root.join(path) gemspecs = Dir[File.join(expanded_path, "#{name}.gemspec")] @@ -146,7 +146,9 @@ module Bundler end def path(path, options = {}, &blk) - with_source(@sources.add_path_source(normalize_hash(options).merge("path" => path_relative_to_gemfile(path))), &blk) + source_options = normalize_hash(options).merge("path" => Pathname.new(path), "root_path" => gemfile_root) + source = @sources.add_path_source(source_options) + with_source(source, &blk) end def git(uri, options = {}, &blk) @@ -315,10 +317,6 @@ module Bundler opts["git"] = @git_sources[git_name].call(opts[git_name]) end - if opts.key?("path") - opts["path"] = path_relative_to_gemfile(opts["path"]) - end - %w(git path).each do |type| next unless param = opts[type] if version.first && version.first =~ /^\s*=?\s*(\d[^\s]*)\s*$/ @@ -494,9 +492,9 @@ module Bundler end end - def path_relative_to_gemfile(path) + def gemfile_root @gemfile ||= Bundler.default_gemfile - @gemfile.dirname + path + @gemfile.dirname end end end diff --git a/lib/bundler/source/path.rb b/lib/bundler/source/path.rb index ebdab3e813..24a01b4060 100644 --- a/lib/bundler/source/path.rb +++ b/lib/bundler/source/path.rb @@ -3,7 +3,7 @@ module Bundler class Path < Source autoload :Installer, "bundler/source/path/installer" - attr_reader :path, :options + attr_reader :path, :options, :root_path attr_writer :name attr_accessor :version @@ -16,6 +16,8 @@ module Bundler @allow_cached = false @allow_remote = false + @root_path = options["root_path"] || Bundler.root + if options["path"] @path = Pathname.new(options["path"]) @path = expand(@path) unless @path.relative? @@ -77,7 +79,7 @@ module Bundler def cache(spec, custom_path = nil) app_cache_path = app_cache_path(custom_path) return unless Bundler.settings[:cache_all] - return if expand(@original_path).to_s.index(Bundler.root.to_s + "/") == 0 + return if expand(@original_path).to_s.index(root_path.to_s + "/") == 0 unless @original_path.exist? raise GemNotFound, "Can't cache gem #{version_message(spec)} because #{self} is missing!" @@ -111,7 +113,7 @@ module Bundler end def expand(somepath) - somepath.expand_path(Bundler.root) + somepath.expand_path(root_path) rescue ArgumentError => e Bundler.ui.debug(e) raise PathError, "There was an error while trying to use the path " \ @@ -164,8 +166,8 @@ module Bundler end def relative_path - if path.to_s.start_with?(Bundler.root.to_s) - return path.relative_path_from(Bundler.root) + if path.to_s.start_with?(root_path.to_s) + return path.relative_path_from(root_path) end path end diff --git a/spec/bundler/dsl_spec.rb b/spec/bundler/dsl_spec.rb index 2d323d64f4..9553c8fd43 100644 --- a/spec/bundler/dsl_spec.rb +++ b/spec/bundler/dsl_spec.rb @@ -235,6 +235,7 @@ describe Bundler::Dsl do it "restores it after it's done" do other_source = double("other-source") allow(Bundler::Source::Rubygems).to receive(:new).and_return(other_source) + allow(Bundler).to receive(:default_gemfile).and_return(Pathname.new("./Gemfile")) subject.source("https://other-source.org") do subject.gem("dobry-pies", :path => "foo") |