Only prepend/append once for hooks

This commit is contained in:
Mitchell Hashimoto 2013-03-30 14:57:42 -07:00
parent c6a2d01cdf
commit e5539eb769
2 changed files with 24 additions and 1 deletions

View File

@ -133,9 +133,22 @@ module Vagrant
if env[:action_hooks]
builder = self.dup
# These are the options to pass into hook application.
options = {}
# If we already ran through once and did append/prepends,
# then don't do it again.
if env[:action_hooks_already_ran]
options[:no_prepend_or_append] = true
end
# Specify that we already ran, so in the future we don't repeat
# the prepend/append hooks.
env[:action_hooks_already_ran] = true
# Apply all the hooks to the new builder instance
env[:action_hooks].each do |hook|
hook.apply(builder)
hook.apply(builder, options)
end
# The stack is now the result of the new builder

View File

@ -191,6 +191,16 @@ describe Vagrant::Action::Builder do
subject.call(data)
data[:data].should == [1, 2]
data[:action_hooks_already_ran].should == true
end
it "applies without prepend/append if it has already" do
hook = double("hook")
hook.should_receive(:apply).with(anything, { :no_prepend_or_append => true }).once
data[:action_hooks] = [hook]
data[:action_hooks_already_ran] = true
subject.call(data)
end
end
end