diff options
author | Asutosh Palai <asupalai@gmail.com> | 2016-07-27 00:24:31 +0530 |
---|---|---|
committer | Asutosh Palai <asupalai@gmail.com> | 2016-08-16 09:48:27 +0530 |
commit | 1cc0050e8a6791bc908fd92199804762aaa43fc7 (patch) | |
tree | fb824c8b36ce8f40c4f8e88c3fa32e00b448dafb | |
parent | b5094c0377cc1cc9642a7f6a477a31c1db304aeb (diff) | |
download | bundler-1cc0050e8a6791bc908fd92199804762aaa43fc7.tar.gz |
Added passing blocks to hooks
-rw-r--r-- | lib/bundler/plugin.rb | 6 | ||||
-rw-r--r-- | spec/bundler/plugin_spec.rb | 14 |
2 files changed, 17 insertions, 3 deletions
diff --git a/lib/bundler/plugin.rb b/lib/bundler/plugin.rb index e022e890e5..bf1996e36a 100644 --- a/lib/bundler/plugin.rb +++ b/lib/bundler/plugin.rb @@ -149,13 +149,13 @@ module Bundler @hooks_by_event[event.to_s] << block end - def hook(event, *args) + def hook(event, *args, &arg_blk) plugins = index.hook_plugins(event) - return unless plugins + return unless plugins.any? (plugins - @loaded_plugin_names).each {|name| load_plugin(name) } - @hooks_by_event[event].each {|blk| blk.call(*args) } + @hooks_by_event[event].each {|blk| blk.call(*args, &arg_blk) } end # currently only intended for specs diff --git a/spec/bundler/plugin_spec.rb b/spec/bundler/plugin_spec.rb index 6ae9465dde..ad0c1979f3 100644 --- a/spec/bundler/plugin_spec.rb +++ b/spec/bundler/plugin_spec.rb @@ -274,5 +274,19 @@ describe Bundler::Plugin do expect(out).to eq("loaded") end end + + context "a block is to be passed" do + let(:code) { <<-RUBY } + Bundler::Plugin::API.hook("#{event}") { |&blk| blk.call } + RUBY + + it "is passed to the hook" do + out = capture(:stdout) do + Plugin.hook("event-1") { puts "win" } + end.strip + + expect(out).to eq("win") + end + end end end |