From e50e264747c1ed23ed40da9f712849531d6283f6 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Sun, 28 Feb 2010 01:47:42 -0800 Subject: [PATCH] Actions can now implement the #cleanup method which is called after all other actions have finished executing. --- lib/vagrant/actions/base.rb | 5 +++++ lib/vagrant/actions/runner.rb | 2 +- test/vagrant/actions/runner_test.rb | 5 +++-- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/vagrant/actions/base.rb b/lib/vagrant/actions/base.rb index ad7fbc777..c6cf3472b 100644 --- a/lib/vagrant/actions/base.rb +++ b/lib/vagrant/actions/base.rb @@ -47,6 +47,11 @@ module Vagrant # @vm.invoke_callback(:after_oven, "more", "than", "one", "option") end + # This method is called after all actions have finished executing. + # It is meant as a place where final cleanup code can be done, knowing + # that all other actions are finished using your data. + def cleanup; end + # This method is only called if some exception occurs in the chain # of actions. If an exception is raised in any action in the current # chain, then every action part of that chain has {#rescue} called diff --git a/lib/vagrant/actions/runner.rb b/lib/vagrant/actions/runner.rb index c6b5aa9fb..ef931626c 100644 --- a/lib/vagrant/actions/runner.rb +++ b/lib/vagrant/actions/runner.rb @@ -41,7 +41,7 @@ module Vagrant # Call the prepare method on each once its # initialized, then call the execute! method begin - [:prepare, :execute!].each do |method| + [:prepare, :execute!, :cleanup].each do |method| actions.each do |action| action.send(method) end diff --git a/test/vagrant/actions/runner_test.rb b/test/vagrant/actions/runner_test.rb index f0cebbfe7..852946bb2 100644 --- a/test/vagrant/actions/runner_test.rb +++ b/test/vagrant/actions/runner_test.rb @@ -5,6 +5,7 @@ class ActionRunnerTest < Test::Unit::TestCase action = mock("action") action.stubs(:prepare) action.stubs(:execute!) + action.stubs(:cleanup) action end @@ -120,7 +121,7 @@ class ActionRunnerTest < Test::Unit::TestCase run_class.expects(:new).once.returns(run_action) @runner.actions << action - [:prepare, :execute!].each do |method| + [:prepare, :execute!, :cleanup].each do |method| action.expects(method).never run_action.expects(method).once end @@ -146,7 +147,7 @@ class ActionRunnerTest < Test::Unit::TestCase actions << action end - [:prepare, :execute!].each do |method| + [:prepare, :execute!, :cleanup].each do |method| actions.each do |action| action.expects(method).once.in_sequence(action_seq) end