Action builder supports indexing middlewares by name

This commit is contained in:
Mitchell Hashimoto 2012-05-05 22:01:53 -07:00
parent c2649074c3
commit 879f98b5d5
2 changed files with 14 additions and 0 deletions

View File

@ -101,6 +101,7 @@ module Vagrant
def index(object)
stack.each_with_index do |item, i|
return i if item[0] == object
return i if item[0].respond_to?(:name) && item[0].name == object
end
nil

View File

@ -73,6 +73,19 @@ describe Vagrant::Action::Builder do
data[:data].should == [2, 1]
end
it "can insert by name" do
# Create the proc then make sure it has a name
bar_proc = appender_proc(2)
def bar_proc.name; :bar; end
instance.use appender_proc(1)
instance.use bar_proc
instance.insert_before :bar, appender_proc(3)
instance.call(data)
data[:data].should == [1, 3, 2]
end
it "can insert next to a previous object" do
proc2 = appender_proc(2)
instance.use appender_proc(1)