diff --git a/lib/vagrant/action/builder.rb b/lib/vagrant/action/builder.rb index c467de445..47a3226d7 100644 --- a/lib/vagrant/action/builder.rb +++ b/lib/vagrant/action/builder.rb @@ -34,8 +34,10 @@ module Vagrant # Returns a mergeable version of the builder. If `use` is called with # the return value of this method, then the stack will merge, instead # of being treated as a separate single middleware. - def mergeable - [:merge, self] + def flatten + lambda do |env| + self.call(env) + end end # Adds a middleware class to the middleware stack. Any additional @@ -44,9 +46,9 @@ module Vagrant # # @param [Class] middleware The middleware class def use(middleware, *args, &block) - if middleware.kind_of?(Array) && middleware[0] == :merge + if middleware.kind_of?(Builder) # Merge in the other builder's stack into our own - self.stack.concat(middleware[1].stack) + self.stack.concat(middleware.stack) else self.stack << [middleware, args, block] end diff --git a/lib/vagrant/action/builtin.rb b/lib/vagrant/action/builtin.rb index f1c01b249..a57f33e58 100644 --- a/lib/vagrant/action/builtin.rb +++ b/lib/vagrant/action/builtin.rb @@ -28,8 +28,8 @@ module Vagrant # reload - Halts then restarts the VM reload = Builder.new do - use Action[:halt].mergeable - use Action[:start].mergeable + use Action[:halt] + use Action[:start] end register :reload, reload @@ -40,14 +40,14 @@ module Vagrant use VM::Persist use VM::MatchMACAddress use VM::CheckGuestAdditions - use Action[:start].mergeable + use Action[:start] end register :up, up # destroy - Halts, cleans up, and destroys an existing VM destroy = Builder.new do - use Action[:halt].mergeable + use Action[:halt] use VM::DestroyUnusedNetworkInterfaces use VM::Destroy end diff --git a/test/vagrant/action/builder_test.rb b/test/vagrant/action/builder_test.rb index d1556a30c..b75f35b80 100644 --- a/test/vagrant/action/builder_test.rb +++ b/test/vagrant/action/builder_test.rb @@ -40,26 +40,22 @@ class ActionBuilderTest < Test::Unit::TestCase use 3 end - @instance.use 1 - @instance.use other.mergeable - assert_equal 3, @instance.stack.length - end - - should "not merge in another builder if not mergeable" do - other = @klass.new do - use 2 - use 3 - end - @instance.use 1 @instance.use other - assert_equal 2, @instance.stack.length + assert_equal 3, @instance.stack.length end end - context "mergeable" do - should "return the merge format with the builder" do - assert_equal [:merge, @instance], @instance.mergeable + context "flatten" do + should "return the flattened format of the builder" do + env = Vagrant::Action::Environment.new(nil) + env.expects(:foo).once + + func = lambda { |x| x.foo } + @instance.use func + proc = @instance.flatten + assert proc.respond_to?(:call) + proc.call(env) end end