diff options
author | Homu <homu@barosl.com> | 2016-08-16 08:42:50 +0900 |
---|---|---|
committer | Homu <homu@barosl.com> | 2016-08-16 08:42:50 +0900 |
commit | f81446d095c60a162ec57c18fd62c29e9567a0a2 (patch) | |
tree | 9fc6e04a3405f99b7855f99dece62e4c96791dc6 /lib | |
parent | 7c38144e84b48cc932756932ad4679c4f71400c0 (diff) | |
parent | 888041af40a9e7a9a173439c41f2961de152b39c (diff) | |
download | bundler-f81446d095c60a162ec57c18fd62c29e9567a0a2.tar.gz |
Auto merge of #4788 - asutoshpalai:plugin-project-level, r=segiddins
Project local plugins
If the user is in an app directory the plugin is installed in `.bundle/` inside the app root.
If the user is in not in any app directory the plugin is installed in the `.bundle/` in the user's home.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/bundler.rb | 3 | ||||
-rw-r--r-- | lib/bundler/plugin.rb | 28 | ||||
-rw-r--r-- | lib/bundler/plugin/index.rb | 31 |
3 files changed, 53 insertions, 9 deletions
diff --git a/lib/bundler.rb b/lib/bundler.rb index f5fdcf87d7..8b3f60d36a 100644 --- a/lib/bundler.rb +++ b/lib/bundler.rb @@ -398,6 +398,9 @@ EOF @locked_gems = nil @bundle_path = nil @bin_path = nil + + Plugin.reset! + return unless defined?(@rubygems) && @rubygems rubygems.undo_replacements rubygems.reset diff --git a/lib/bundler/plugin.rb b/lib/bundler/plugin.rb index f5366d2a13..cd3843fc0d 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..918b3a4392 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, true) + 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,23 @@ module Bundler # Reads the index file from the directory and initializes the instance # variables. - def load_index + # + # It skips the sources if the second param is true + # @param [Pathname] index file path + # @param [Boolean] is the index file global index + def load_index(index_file, global = false) 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"]) unless global end end |