summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAsutosh Palai <asupalai@gmail.com>2016-07-27 00:00:32 +0530
committerAsutosh Palai <asupalai@gmail.com>2016-08-16 09:48:27 +0530
commitb5094c0377cc1cc9642a7f6a477a31c1db304aeb (patch)
tree829d431dd9a386a6962420506a87c87f0ad6c92c
parentdf68550b599a700419a5fcdb6b9249156f5ac046 (diff)
downloadbundler-b5094c0377cc1cc9642a7f6a477a31c1db304aeb.tar.gz
Incorporated suggestions
-rw-r--r--lib/bundler.rb1
-rw-r--r--lib/bundler/installer.rb1
-rw-r--r--lib/bundler/plugin.rb45
-rw-r--r--lib/bundler/plugin/index.rb17
-rw-r--r--spec/bundler/plugin/index_spec.rb2
-rw-r--r--spec/bundler/plugin_spec.rb4
-rw-r--r--spec/plugins/hook_spec.rb4
7 files changed, 36 insertions, 38 deletions
diff --git a/lib/bundler.rb b/lib/bundler.rb
index 6a39a6359d..8b3f60d36a 100644
--- a/lib/bundler.rb
+++ b/lib/bundler.rb
@@ -405,7 +405,6 @@ EOF
rubygems.undo_replacements
rubygems.reset
@rubygems = nil
- Plugin.reset!
end
private
diff --git a/lib/bundler/installer.rb b/lib/bundler/installer.rb
index aa0c5f1c8e..528dee177e 100644
--- a/lib/bundler/installer.rb
+++ b/lib/bundler/installer.rb
@@ -20,6 +20,7 @@ module Bundler
# For more information see the #run method on this class.
def self.install(root, definition, options = {})
installer = new(root, definition)
+ Plugin.hook("before-install-all", definition.dependencies)
installer.run(options)
installer
end
diff --git a/lib/bundler/plugin.rb b/lib/bundler/plugin.rb
index 54a9ac33a4..e022e890e5 100644
--- a/lib/bundler/plugin.rb
+++ b/lib/bundler/plugin.rb
@@ -16,10 +16,16 @@ module Bundler
module_function
- @commands = {}
- @sources = {}
- @hooks = {}
- @loaded = []
+ def reset!
+ instance_variables.each {|i| remove_instance_variable(i) }
+
+ @sources = {}
+ @commands = {}
+ @hooks_by_event = Hash.new {|h, k| h[k] = [] }
+ @loaded_plugin_names = []
+ end
+
+ reset!
# Installs a new plugin by the given name
#
@@ -32,7 +38,7 @@ module Bundler
save_plugins names, specs
rescue PluginError => e
specs.values.map {|spec| Bundler.rm_rf(spec.full_gem_path) } if specs
- Bundler.ui.error "Failed to install plugin #{name}: #{e.message}\n #{e.backtrace[0]}"
+ Bundler.ui.error "Failed to install plugin #{name}: #{e.message}\n #{e.backtrace.join("\n")}"
end
# Evaluates the Gemfile with a limited DSL and installs the plugins
@@ -140,16 +146,16 @@ module Bundler
end
def add_hook(event, &block)
- (@hooks[event.to_s] ||= []) << block
+ @hooks_by_event[event.to_s] << block
end
def hook(event, *args)
plugins = index.hook_plugins(event)
return unless plugins
- (plugins - @loaded).each {|name| load_plugin(name) }
+ (plugins - @loaded_plugin_names).each {|name| load_plugin(name) }
- @hooks[event].each {|blk| blk.call(*args) }
+ @hooks_by_event[event].each {|blk| blk.call(*args) }
end
# currently only intended for specs
@@ -159,15 +165,6 @@ module Bundler
Index.new.installed?(plugin)
end
- def reset!
- instance_variables.each {|i| remove_instance_variable(i) }
-
- @sources = {}
- @commands = {}
- @hooks = {}
- @loaded = []
- end
-
# Post installation processing and registering with index
#
# @param [Array<String>] plugins list to be installed
@@ -178,7 +175,7 @@ module Bundler
plugins.each do |name|
spec = specs[name]
validate_plugin! Pathname.new(spec.full_gem_path)
- installed = register_plugin name, spec, optional_plugins.include?(name)
+ installed = register_plugin(name, spec, optional_plugins.include?(name))
Bundler.ui.info "Installed plugin #{name}" if installed
end
end
@@ -206,11 +203,11 @@ module Bundler
def register_plugin(name, spec, optional_plugin = false)
commands = @commands
sources = @sources
- hooks = @hooks
+ hooks = @hooks_by_event
@commands = {}
@sources = {}
- @hooks = {}
+ @hooks_by_event = Hash.new {|h, k| h[k] = [] }
load_paths = spec.load_paths
add_to_load_path(load_paths)
@@ -226,14 +223,14 @@ module Bundler
Bundler.rm_rf(path)
false
else
- index.register_plugin name, path.to_s, load_paths, @commands.keys,
- @sources.keys, @hooks.keys
+ index.register_plugin(name, path.to_s, load_paths, @commands.keys,
+ @sources.keys, @hooks_by_event.keys)
true
end
ensure
@commands = commands
@sources = sources
- @hooks = hooks
+ @hooks_by_event = hooks
end
# Executes the plugins.rb file
@@ -249,7 +246,7 @@ module Bundler
load path.join(PLUGIN_FILE_NAME)
- @loaded << name
+ @loaded_plugin_names << name
rescue => e
Bundler.ui.error "Failed loading plugin #{name}: #{e.message}"
raise
diff --git a/lib/bundler/plugin/index.rb b/lib/bundler/plugin/index.rb
index 455fb7b775..35851a3df9 100644
--- a/lib/bundler/plugin/index.rb
+++ b/lib/bundler/plugin/index.rb
@@ -24,7 +24,7 @@ module Bundler
@plugin_paths = {}
@commands = {}
@sources = {}
- @hooks = {}
+ @hooks = Hash.new {|h, k| h[k] = [] }
@load_paths = {}
load_index(global_index_file, true)
@@ -51,7 +51,7 @@ module Bundler
raise SourceConflict.new(name, common) unless common.empty?
sources.each {|k| @sources[k] = name }
- hooks.each {|e| (@hooks[e] ||= []) << name }
+ hooks.each {|e| @hooks[e] << name }
@plugin_paths[name] = path
@load_paths[name] = load_paths
@@ -119,14 +119,15 @@ module Bundler
break unless valid_file
data = index_f.read
+
require "bundler/yaml_serializer"
index = YAMLSerializer.load(data)
- @plugin_paths.merge!(index["plugin_paths"])
- @load_paths.merge!(index["load_paths"])
@commands.merge!(index["commands"])
- @sources.merge!(index["sources"]) unless global
@hooks.merge!(index["hooks"])
+ @load_paths.merge!(index["load_paths"])
+ @plugin_paths.merge!(index["plugin_paths"])
+ @sources.merge!(index["sources"]) unless global
end
end
@@ -135,11 +136,11 @@ module Bundler
# to be only String key value pairs)
def save_index
index = {
- "plugin_paths" => @plugin_paths,
- "load_paths" => @load_paths,
"commands" => @commands,
- "sources" => @sources,
"hooks" => @hooks,
+ "load_paths" => @load_paths,
+ "plugin_paths" => @plugin_paths,
+ "sources" => @sources,
}
require "bundler/yaml_serializer"
diff --git a/spec/bundler/plugin/index_spec.rb b/spec/bundler/plugin/index_spec.rb
index ffd18b2039..9c962affc6 100644
--- a/spec/bundler/plugin/index_spec.rb
+++ b/spec/bundler/plugin/index_spec.rb
@@ -122,7 +122,7 @@ describe Bundler::Plugin::Index do
end
it "the hook" do
- expect(index.hook_plugins("xhoook")).to be_falsy
+ expect(index.hook_plugins("xhoook")).to be_empty
end
end
diff --git a/spec/bundler/plugin_spec.rb b/spec/bundler/plugin_spec.rb
index ab0bbf4095..6ae9465dde 100644
--- a/spec/bundler/plugin_spec.rb
+++ b/spec/bundler/plugin_spec.rb
@@ -249,7 +249,7 @@ describe Bundler::Plugin do
let(:event) { "event-1" }
it "executes the hook" do
- out = capture_output do
+ out = capture(:stdout) do
Plugin.hook("event-1")
end.strip
@@ -266,7 +266,7 @@ describe Bundler::Plugin do
let(:event) { /event-1|event-2/ }
it "evals plugins.rb once" do
- out = capture_output do
+ out = capture(:stdout) do
Plugin.hook("event-1")
Plugin.hook("event-2")
end.strip
diff --git a/spec/plugins/hook_spec.rb b/spec/plugins/hook_spec.rb
index 44ceab232d..bafe688d5e 100644
--- a/spec/plugins/hook_spec.rb
+++ b/spec/plugins/hook_spec.rb
@@ -19,10 +19,10 @@ describe "hook plugins" do
it "runs after a rubygem is installed" do
install_gemfile <<-G
source "file://#{gem_repo1}"
- gem "yaml_spec"
gem "rake"
+ gem "rack"
G
- expect(out).to include "gems to be installed yaml_spec, rake"
+ expect(out).to include "gems to be installed rake, rack"
end
end