From f5cc112a4b7ff911b1d531b18ff9df634efb1f45 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Sun, 24 Nov 2013 21:01:41 -0800 Subject: [PATCH] core: allow hooks to send arbitrary data --- lib/vagrant/environment.rb | 14 +++++++------- test/unit/vagrant/environment_test.rb | 10 +++++++++- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/lib/vagrant/environment.rb b/lib/vagrant/environment.rb index 4628c5233..cc65afa58 100644 --- a/lib/vagrant/environment.rb +++ b/lib/vagrant/environment.rb @@ -133,7 +133,7 @@ module Vagrant # Call the hooks that does not require configurations to be loaded # by using a "clean" action runner - hook(:environment_plugins_loaded, Action::Runner.new(env: self)) + hook(:environment_plugins_loaded, runner: Action::Runner.new(env: self)) # Call the environment load hooks hook(:environment_load) @@ -273,14 +273,14 @@ module Vagrant # # @param [Symbol] name Name of the hook. # @param [Action::Runner] action_runner A custom action runner for running hooks. - def hook(name, runner=nil) + def hook(name, opts=nil) @logger.info("Running hook: #{name}") callable = Action::Builder.new - runner ||= action_runner - runner.run( - callable, - :action_name => name, - :env => self) + opts ||= {} + opts[:runner] ||= action_runner + opts[:action_name] = name + opts[:env] = self + opts.delete(:runner).run(callable, opts) end # This returns a machine with the proper provider for this environment. diff --git a/test/unit/vagrant/environment_test.rb b/test/unit/vagrant/environment_test.rb index 5b0a732c4..13ba2c9a3 100644 --- a/test/unit/vagrant/environment_test.rb +++ b/test/unit/vagrant/environment_test.rb @@ -314,7 +314,15 @@ describe Vagrant::Environment do other_runner = mock other_runner.should_receive(:run).and_return(:foo) - instance.hook(:bar, other_runner).should == :foo + instance.hook(:bar, runner: other_runner).should == :foo + end + + it "should allow passing in custom data" do + instance.action_runner.should_receive(:run).with do |callable, env| + env[:foo].should == :bar + end + + instance.hook(:foo, foo: :bar) end end