diff options
author | Asutosh Palai <asupalai@gmail.com> | 2016-07-15 13:50:48 +0530 |
---|---|---|
committer | Asutosh Palai <asupalai@gmail.com> | 2016-07-21 09:53:08 +0530 |
commit | 2b6400a6d8cbccf2e917d993dd50e4cc1269d9ad (patch) | |
tree | 167e0f81aed75aac23362b02cc959eec0b190e9e | |
parent | 2a138ed736b2210a21588db44b567dbdea6f7a18 (diff) | |
download | bundler-2b6400a6d8cbccf2e917d993dd50e4cc1269d9ad.tar.gz |
Adding app index for plugin
-rw-r--r-- | lib/bundler/plugin.rb | 28 | ||||
-rw-r--r-- | lib/bundler/plugin/index.rb | 27 | ||||
-rw-r--r-- | spec/bundler/plugin_spec.rb | 21 | ||||
-rw-r--r-- | spec/plugins/install_spec.rb | 2 | ||||
-rw-r--r-- | spec/support/path.rb | 8 |
5 files changed, 72 insertions, 14 deletions
diff --git a/lib/bundler/plugin.rb b/lib/bundler/plugin.rb index f5366d2a13..64cdf94a11 100644 --- a/lib/bundler/plugin.rb +++ b/lib/bundler/plugin.rb @@ -63,9 +63,25 @@ module Bundler @index ||= Index.new end - # The directory root to all plugin related data + # The directory root for all plugin related data + # + # Points to root in app_config_path if ran in an app else points to the one + # in user_bundle_path def root - @root ||= Bundler.user_bundle_path.join("plugin") + @root ||= if SharedHelpers.in_bundle? + local_root + else + global_root + end + end + + def local_root + Bundler.app_config_path.join("plugin") + end + + # The global directory root for all plugin related data + def global_root + Bundler.user_bundle_path.join("plugin") end # The cache directory for plugin stuffs @@ -128,6 +144,14 @@ module Bundler Index.new.installed?(plugin) end + # Used by specs + def reset! + instance_variables.each {|i| remove_instance_variable(i)} + + @sources = {} + @commands = {} + end + # Post installation processing and registering with index # # @param [Array<String>] plugins list to be installed diff --git a/lib/bundler/plugin/index.rb b/lib/bundler/plugin/index.rb index 4abf85fb02..6a75173e3a 100644 --- a/lib/bundler/plugin/index.rb +++ b/lib/bundler/plugin/index.rb @@ -26,7 +26,8 @@ module Bundler @sources = {} @load_paths = {} - load_index + load_index(global_index_file) + load_index(local_index_file) if SharedHelpers.in_bundle? end # This function is to be called when a new plugin is installed. This @@ -57,11 +58,21 @@ module Bundler raise end - # Path where the index file is stored + # Path of default index file def index_file Plugin.root.join("index") end + # Path where the global index file is stored + def global_index_file + Plugin.global_root.join("index") + end + + # Path where the local index file is stored + def local_index_file + Plugin.local_root.join("index") + end + def plugin_path(name) Pathname.new @plugin_paths[name] end @@ -91,17 +102,19 @@ module Bundler # Reads the index file from the directory and initializes the instance # variables. - def load_index + def load_index(index_file) SharedHelpers.filesystem_access(index_file, :read) do |index_f| valid_file = index_f && index_f.exist? && !index_f.size.zero? break unless valid_file + data = index_f.read require "bundler/yaml_serializer" index = YAMLSerializer.load(data) - @plugin_paths = index["plugin_paths"] || {} - @load_paths = index["load_paths"] || {} - @commands = index["commands"] || {} - @sources = index["sources"] || {} + + @plugin_paths.merge!(index["plugin_paths"]) + @load_paths.merge!(index["load_paths"]) + @commands.merge!(index["commands"]) + @sources.merge!(index["sources"]) end end diff --git a/spec/bundler/plugin_spec.rb b/spec/bundler/plugin_spec.rb index 0c81df2232..4f09943773 100644 --- a/spec/bundler/plugin_spec.rb +++ b/spec/bundler/plugin_spec.rb @@ -10,6 +10,8 @@ describe Bundler::Plugin do let(:spec2) { double(:spec2) } before do + Plugin.reset! + build_lib "new-plugin", :path => lib_path("new-plugin") do |s| s.write "plugins.rb" end @@ -209,4 +211,23 @@ describe Bundler::Plugin do expect(subject.source_from_lock(opts)).to be(s_instance) end end + + describe "#root" do + context "in app dir" do + before do + gemfile "" + end + + it "returns plugin dir in app .bundle path" do + expect(subject.root).to eq(bundled_app.join(".bundle/plugin")) + end + end + + context "outside app dir" do + it "returns plugin dir in global bundle path" do + Dir.chdir tmp + expect(subject.root).to eq(home.join(".bundle/plugin")) + end + end + end end diff --git a/spec/plugins/install_spec.rb b/spec/plugins/install_spec.rb index eaf6427577..b700ee0fe3 100644 --- a/spec/plugins/install_spec.rb +++ b/spec/plugins/install_spec.rb @@ -176,7 +176,7 @@ describe "bundler plugin install" do RUBY ruby code - plugin_should_be_installed("foo") + expect(local_plugin_gems("foo-1.0", "plugins.rb")).to exist end end end diff --git a/spec/support/path.rb b/spec/support/path.rb index 4aa99ee118..d8b1384ede 100644 --- a/spec/support/path.rb +++ b/spec/support/path.rb @@ -81,12 +81,12 @@ module Spec Pathname.new(File.expand_path("../../../lib", __FILE__)) end - def plugin_root(*args) - home ".bundle", "plugin", *args + def local_plugin_root(*args) + bundled_app ".bundle", "plugin", *args end - def plugin_gems(*args) - plugin_root "gems", *args + def local_plugin_gems(*args) + local_plugin_root "gems", *args end extend self |