Environment#hook allows hooks to be run at arbitrary points
This commit is contained in:
parent
c68bf33d66
commit
3c343c0623
|
@ -124,6 +124,9 @@ module Vagrant
|
||||||
|
|
||||||
# Load the plugins
|
# Load the plugins
|
||||||
load_plugins
|
load_plugins
|
||||||
|
|
||||||
|
# Call the environment load hooks
|
||||||
|
hook(:environment_load)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Return a human-friendly string for pretty printed or inspected
|
# Return a human-friendly string for pretty printed or inspected
|
||||||
|
@ -236,6 +239,15 @@ module Vagrant
|
||||||
@config_global
|
@config_global
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# This defines a hook point where plugin action hooks that are registered
|
||||||
|
# against the given name will be run in the context of this environment.
|
||||||
|
#
|
||||||
|
# @param [Symbol] name Name of the hook.
|
||||||
|
def hook(name)
|
||||||
|
callable = Proc.new {}
|
||||||
|
action_runner.run(callable, :action_name => name)
|
||||||
|
end
|
||||||
|
|
||||||
# This returns a machine with the proper provider for this environment.
|
# This returns a machine with the proper provider for this environment.
|
||||||
# The machine named by `name` must be in this environment.
|
# The machine named by `name` must be in this environment.
|
||||||
#
|
#
|
||||||
|
|
|
@ -205,6 +205,18 @@ describe Vagrant::Environment do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "#hook" do
|
||||||
|
it "should call the action runner with the proper hook" do
|
||||||
|
hook_name = :foo
|
||||||
|
|
||||||
|
instance.action_runner.should_receive(:run).with do |callable, env|
|
||||||
|
env[:action_name].should == hook_name
|
||||||
|
end
|
||||||
|
|
||||||
|
instance.hook(hook_name)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
describe "primary machine name" do
|
describe "primary machine name" do
|
||||||
it "should be the only machine if not a multi-machine environment" do
|
it "should be the only machine if not a multi-machine environment" do
|
||||||
instance.primary_machine_name.should == instance.machine_names.first
|
instance.primary_machine_name.should == instance.machine_names.first
|
||||||
|
|
Loading…
Reference in New Issue