From 879f98b5d5a3a9b09fe8a38dd92c71a5c4183161 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Sat, 5 May 2012 22:01:53 -0700 Subject: [PATCH] Action builder supports indexing middlewares by name --- lib/vagrant/action/builder.rb | 1 + test/unit/vagrant/action/builder_test.rb | 13 +++++++++++++ 2 files changed, 14 insertions(+) diff --git a/lib/vagrant/action/builder.rb b/lib/vagrant/action/builder.rb index d38ad45b6..2b54115ff 100644 --- a/lib/vagrant/action/builder.rb +++ b/lib/vagrant/action/builder.rb @@ -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 diff --git a/test/unit/vagrant/action/builder_test.rb b/test/unit/vagrant/action/builder_test.rb index 6c7def551..66bcd9897 100644 --- a/test/unit/vagrant/action/builder_test.rb +++ b/test/unit/vagrant/action/builder_test.rb @@ -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)