diff options
author | Asutosh Palai <asupalai@gmail.com> | 2016-05-20 20:31:58 +0530 |
---|---|---|
committer | Asutosh Palai <asupalai@gmail.com> | 2016-05-24 21:15:01 +0530 |
commit | 724833e6b0ed61f66478718f1071ac2887cf261d (patch) | |
tree | a4f2f525cbcec1427c56e038445f96c7a82e064f | |
parent | d65b6cea7076d17e7ab49d6391d16389e36cbeeb (diff) | |
download | bundler-724833e6b0ed61f66478718f1071ac2887cf261d.tar.gz |
Added index file
-rw-r--r-- | lib/bundler/plugin.rb | 24 | ||||
-rw-r--r-- | lib/bundler/plugin/index.rb | 43 |
2 files changed, 63 insertions, 4 deletions
diff --git a/lib/bundler/plugin.rb b/lib/bundler/plugin.rb index 364401ded1..4e994c6d01 100644 --- a/lib/bundler/plugin.rb +++ b/lib/bundler/plugin.rb @@ -2,6 +2,7 @@ module Bundler class Plugin + autoload :Index, "bundler/plugin/index" class << self @@ -11,23 +12,38 @@ module Bundler source = options[:source] || raise(ArgumentError, "You need to provide the source") version = options[:version] || [">= 0"] - plugin_path = Installer.install(name, source, version) + plugin_path = Pathname.new Installer.install(name, source, version) - puts plugin_path + validate_plugin! plugin_path + + register_plugin name, plugin_path Bundler.ui.info "Installed plugin #{name}" rescue StandardError => e + Bundler.rm_rf(plugin_path) if plugin_path Bundler.ui.error "Failed to install plugin #{name}: #{e.message}\n #{e.backtrace.join("\n ")}" - Bundler.ui.trace e end + def validate_plugin! plugin_path + unless File.file? plugin_path.join("plugin.rb") + raise "plugin.rb was not found in the plugin gem!" + end + end + + def register_plugin name, path + index.register_plugin name, path + end + + def index + @index ||= Index.new + end def root @root ||= Bundler.user_bundle_path.join("plugin") end def cache - @cache ||= root.join "cache" + @cache ||= root.join("cache") end end end diff --git a/lib/bundler/plugin/index.rb b/lib/bundler/plugin/index.rb new file mode 100644 index 0000000000..d548475064 --- /dev/null +++ b/lib/bundler/plugin/index.rb @@ -0,0 +1,43 @@ +# forzen_string_literal: true +require "yaml" + +module Bundler + class Plugin::Index + + def initialize + @plugin_sources = {} + + load_index + end + + def load_index + SharedHelpers.filesystem_access(index_file, :read) do |index_f| + valid_file = index_f && index_f.exist? && !index_f.size.zero? + return unless valid_file + index = YAML.load_file(index_f) + @plugin_sources = index[:plugin_sources] + end + end + + def save_index + index = { + :plugin_sources => @plugin_sources + } + + SharedHelpers.filesystem_access(index_file) do |index_f| + FileUtils.mkdir_p(index_f.dirname) + File.open(index_f, "w") { |f| f.puts YAML.dump(index) } + end + end + + def register_plugin(name, path) + @plugin_sources[name] = path + + save_index + end + + def index_file + Plugin.root.join("index") + end + end +end |