diff options
author | Asutosh Palai <asupalai@gmail.com> | 2016-06-20 21:27:22 +0530 |
---|---|---|
committer | Asutosh Palai <asupalai@gmail.com> | 2016-07-03 09:40:59 +0530 |
commit | 07d843a4794bce29d0bec7bb30e35d8b47f90b90 (patch) | |
tree | 70e21a47fb1beb7542d63f85916ba68ca0902a73 /lib | |
parent | 4d2a6771c6bf31929f028ec627caecbc35434553 (diff) | |
download | bundler-07d843a4794bce29d0bec7bb30e35d8b47f90b90.tar.gz |
Made the auto added source plugins optional
Diffstat (limited to 'lib')
-rw-r--r-- | lib/bundler/plugin.rb | 24 | ||||
-rw-r--r-- | lib/bundler/plugin/dsl.rb | 7 |
2 files changed, 22 insertions, 9 deletions
diff --git a/lib/bundler/plugin.rb b/lib/bundler/plugin.rb index 8d12703e83..abeb854abe 100644 --- a/lib/bundler/plugin.rb +++ b/lib/bundler/plugin.rb @@ -39,18 +39,19 @@ module Bundler # # @param [Pathname] gemfile path def gemfile_install(gemfile = nil, &inline) + builder = DSL.new if block_given? - builder = DSL.new builder.instance_eval(&inline) - definition = builder.to_definition(nil, true) else - definition = DSL.evaluate(gemfile, nil, {}) + builder.eval_gemfile(gemfile) end + definition = builder.to_definition(nil, true) + return if definition.dependencies.empty? plugins = Installer.new.install_definition(definition) - save_plugins plugins + save_plugins plugins, builder.auto_plugins end # The index object used to store the details about the plugin @@ -126,11 +127,12 @@ module Bundler # Post installation processing and registering with index # # @param [Hash] plugins mapped to their installtion path - def save_plugins(plugins) + # @param [Array<String>] names of auto added source plugins that can be ignored + def save_plugins(plugins, optionals = []) plugins.each do |name, path| path = Pathname.new path validate_plugin! path - register_plugin name, path + register_plugin name, path, optionals.include?(name) Bundler.ui.info "Installed plugin #{name}" end end @@ -151,7 +153,9 @@ module Bundler # # @param [String] name the name of the plugin # @param [Pathname] path the path where the plugin is installed at - def register_plugin(name, path) + # @param [Boolean] optional_plugin, removed if there is conflict (used for + # default source plugins) + def register_plugin(name, path, optional) commands = @commands sources = @sources @@ -164,7 +168,11 @@ module Bundler raise MalformattedPlugin, "#{e.class}: #{e.message}" end - index.register_plugin name, path.to_s, @commands.keys, @sources.keys + if optional && @sources.keys.any? { |s| source? s } + Bundler.rm_rf(path) + else + index.register_plugin name, path.to_s, @commands.keys, @sources.keys + end ensure @commands = commands @sources = sources diff --git a/lib/bundler/plugin/dsl.rb b/lib/bundler/plugin/dsl.rb index 123ad557b4..b734df3a03 100644 --- a/lib/bundler/plugin/dsl.rb +++ b/lib/bundler/plugin/dsl.rb @@ -12,9 +12,12 @@ module Bundler # They will be handled by method_missing [:gemspec, :gem, :path, :install_if, :platforms, :env].each {|m| undef_method m } + attr_reader :auto_plugins + def initialize super @sources = Plugin::SourceList.new + @auto_plugins = [] # The source plugins inferred from :type end def plugin(name, *args) @@ -30,7 +33,9 @@ module Bundler options = normalize_hash(options) return super unless options.key?("type") - plugin("bundler-source-#{options["type"]}") unless Plugin.source? options["type"] + plugin_name = "bundler-source-#{options["type"]}" + plugin(plugin_name) + @auto_plugins << plugin_name end end end |