Call built-in supports args for imddleware

This commit is contained in:
Mitchell Hashimoto 2013-01-22 12:20:02 -08:00
parent fb875ab642
commit 6a3c0bd425
2 changed files with 26 additions and 2 deletions

View File

@ -23,11 +23,12 @@ module Vagrant
# can be a class, a lambda, or an object that responds to `call`. # can be a class, a lambda, or an object that responds to `call`.
# @yield [result, builder] This block is expected to build on `builder` # @yield [result, builder] This block is expected to build on `builder`
# which is the next middleware sequence that will be run. # which is the next middleware sequence that will be run.
def initialize(app, env, callable, &block) def initialize(app, env, callable, *callable_args, &block)
raise ArgumentError, "A block must be given to Call" if !block raise ArgumentError, "A block must be given to Call" if !block
@app = app @app = app
@callable = callable @callable = callable
@callable_args = callable_args
@block = block @block = block
@child_app = nil @child_app = nil
end end
@ -35,8 +36,11 @@ module Vagrant
def call(env) def call(env)
runner = Runner.new runner = Runner.new
# Build the callable that we'll run
callable = Builder.build(@callable, *@callable_args)
# Run our callable with our environment # Run our callable with our environment
new_env = runner.run(@callable, env) new_env = runner.run(callable, env)
# Build our new builder based on the result # Build our new builder based on the result
builder = Builder.new builder = Builder.new

View File

@ -53,6 +53,26 @@ describe Vagrant::Action::Builtin::Call do
received.should == :bar received.should == :bar
end end
it "should instantiate the callable with the extra args" do
env = {}
callable = Class.new do
def initialize(app, env, arg)
env[:arg] = arg
end
def call(env); end
end
result = nil
instance = described_class.new(app, env, callable, :foo) do |inner_env, _builder|
result = inner_env[:arg]
end
instance.call(env)
result.should == :foo
end
it "should call the recover method for the sequence in an error" do it "should call the recover method for the sequence in an error" do
# Basic variables # Basic variables
callable = lambda { |env| } callable = lambda { |env| }