Allow disabling prepend/append hooks

This commit is contained in:
Mitchell Hashimoto 2013-03-30 14:51:10 -07:00
parent 7e1c313ff5
commit c6a2d01cdf
2 changed files with 31 additions and 8 deletions

View File

@ -69,15 +69,19 @@ module Vagrant
# called directly.
#
# @param [Builder] builder
def apply(builder)
# Prepends first
@prepend_hooks.each do |klass, args, block|
builder.insert(0, klass, *args, &block)
end
def apply(builder, options=nil)
options ||= {}
# Appends
@append_hooks.each do |klass, args, block|
builder.use(klass, *args, &block)
if !options[:no_prepend_or_append]
# Prepends first
@prepend_hooks.each do |klass, args, block|
builder.insert(0, klass, *args, &block)
end
# Appends
@append_hooks.each do |klass, args, block|
builder.use(klass, *args, &block)
end
end
# Before hooks

View File

@ -97,5 +97,24 @@ describe Vagrant::Action::Hook do
["9", [], nil]
]
end
it "should not prepend or append if disabled" do
builder.use("3")
builder.use("8")
subject.prepend("1", 2)
subject.append("9")
subject.after("3", "4")
subject.before("8", "7")
subject.apply(builder, no_prepend_or_append: true)
builder.stack.should == [
["3", [], nil],
["4", [], nil],
["7", [], nil],
["8", [], nil]
]
end
end
end