From bbe7b3ffc52f779317c3717635b954e92b84f52f Mon Sep 17 00:00:00 2001 From: Fabio Rehm Date: Fri, 18 Oct 2013 18:37:29 -0300 Subject: [PATCH 1/2] core: Add support for plugins to hook into the environment load process before configurations are parsed --- lib/vagrant/environment.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/vagrant/environment.rb b/lib/vagrant/environment.rb index 677d5c971..dc2d7a8a1 100644 --- a/lib/vagrant/environment.rb +++ b/lib/vagrant/environment.rb @@ -131,6 +131,10 @@ module Vagrant # Load the plugins load_plugins + # Call the hooks that does not require configurations to be loaded + # by using a "clean" action runner + hook(:environment_plugins_loaded, Action::Runner.new) + # Call the environment load hooks hook(:environment_load) end @@ -268,10 +272,10 @@ module Vagrant # against the given name will be run in the context of this environment. # # @param [Symbol] name Name of the hook. - def hook(name) + def hook(name, runner = action_runner) @logger.info("Running hook: #{name}") callable = Action::Builder.new - action_runner.run( + runner.run( callable, :action_name => name, :env => self) From a0c1cc02314bc3762e86d3bc98bf3657a5598e76 Mon Sep 17 00:00:00 2001 From: Fabio Rehm Date: Tue, 29 Oct 2013 13:28:04 -0200 Subject: [PATCH 2/2] core: Add spec for running environment hooks with a custom Action::Runner --- lib/vagrant/environment.rb | 1 + test/unit/vagrant/environment_test.rb | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/lib/vagrant/environment.rb b/lib/vagrant/environment.rb index dc2d7a8a1..b92b00748 100644 --- a/lib/vagrant/environment.rb +++ b/lib/vagrant/environment.rb @@ -272,6 +272,7 @@ module Vagrant # against the given name will be run in the context of this environment. # # @param [Symbol] name Name of the hook. + # @param [Action::Runner] action_runner A custom action runner for running hooks. def hook(name, runner = action_runner) @logger.info("Running hook: #{name}") callable = Action::Builder.new diff --git a/test/unit/vagrant/environment_test.rb b/test/unit/vagrant/environment_test.rb index 5f571f7cb..07bd261fa 100644 --- a/test/unit/vagrant/environment_test.rb +++ b/test/unit/vagrant/environment_test.rb @@ -308,6 +308,14 @@ describe Vagrant::Environment do instance.hook(:bar).should == :foo end + + it "should allow passing in a custom action runner" do + instance.action_runner.should_not_receive(:run) + other_runner = mock + other_runner.should_receive(:run).with(:bar).and_return(:foo) + + instance.hook(:bar, other_runner).should == :foo + end end describe "primary machine name" do