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 /lib | |
parent | 2a138ed736b2210a21588db44b567dbdea6f7a18 (diff) | |
download | bundler-2b6400a6d8cbccf2e917d993dd50e4cc1269d9ad.tar.gz |
Adding app index for plugin
Diffstat (limited to 'lib')
-rw-r--r-- | lib/bundler/plugin.rb | 28 | ||||
-rw-r--r-- | lib/bundler/plugin/index.rb | 27 |
2 files changed, 46 insertions, 9 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 |