core: allow hooks to send arbitrary data
This commit is contained in:
parent
6baab10df4
commit
f5cc112a4b
|
@ -133,7 +133,7 @@ module Vagrant
|
||||||
|
|
||||||
# Call the hooks that does not require configurations to be loaded
|
# Call the hooks that does not require configurations to be loaded
|
||||||
# by using a "clean" action runner
|
# 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
|
# Call the environment load hooks
|
||||||
hook(:environment_load)
|
hook(:environment_load)
|
||||||
|
@ -273,14 +273,14 @@ module Vagrant
|
||||||
#
|
#
|
||||||
# @param [Symbol] name Name of the hook.
|
# @param [Symbol] name Name of the hook.
|
||||||
# @param [Action::Runner] action_runner A custom action runner for running hooks.
|
# @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}")
|
@logger.info("Running hook: #{name}")
|
||||||
callable = Action::Builder.new
|
callable = Action::Builder.new
|
||||||
runner ||= action_runner
|
opts ||= {}
|
||||||
runner.run(
|
opts[:runner] ||= action_runner
|
||||||
callable,
|
opts[:action_name] = name
|
||||||
:action_name => name,
|
opts[:env] = self
|
||||||
:env => self)
|
opts.delete(:runner).run(callable, opts)
|
||||||
end
|
end
|
||||||
|
|
||||||
# This returns a machine with the proper provider for this environment.
|
# This returns a machine with the proper provider for this environment.
|
||||||
|
|
|
@ -314,7 +314,15 @@ describe Vagrant::Environment do
|
||||||
other_runner = mock
|
other_runner = mock
|
||||||
other_runner.should_receive(:run).and_return(:foo)
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue