core: allow hooks to send arbitrary data

This commit is contained in:
Mitchell Hashimoto 2013-11-24 21:01:41 -08:00
parent 6baab10df4
commit f5cc112a4b
2 changed files with 16 additions and 8 deletions

View File

@ -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.

View File

@ -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