Call properly modifies original environment
This commit is contained in:
parent
4a1a990491
commit
cd3d2a1e8c
|
@ -2,7 +2,6 @@ require 'vagrant/action/builder'
|
||||||
|
|
||||||
module Vagrant
|
module Vagrant
|
||||||
module Action
|
module Action
|
||||||
autoload :Environment, 'vagrant/action/environment'
|
|
||||||
autoload :Runner, 'vagrant/action/runner'
|
autoload :Runner, 'vagrant/action/runner'
|
||||||
autoload :Warden, 'vagrant/action/warden'
|
autoload :Warden, 'vagrant/action/warden'
|
||||||
|
|
||||||
|
|
|
@ -50,8 +50,11 @@ module Vagrant
|
||||||
@child_app = builder.to_app(new_env)
|
@child_app = builder.to_app(new_env)
|
||||||
final_env = runner.run(@child_app, new_env)
|
final_env = runner.run(@child_app, new_env)
|
||||||
|
|
||||||
|
# Merge the environment into our original environment
|
||||||
|
env.merge!(final_env)
|
||||||
|
|
||||||
# Call the next step using our final environment
|
# Call the next step using our final environment
|
||||||
@app.call(final_env)
|
@app.call(env)
|
||||||
end
|
end
|
||||||
|
|
||||||
def recover(env)
|
def recover(env)
|
||||||
|
|
|
@ -1,12 +0,0 @@
|
||||||
require 'vagrant/util/hash_with_indifferent_access'
|
|
||||||
|
|
||||||
module Vagrant
|
|
||||||
module Action
|
|
||||||
# Represents an action environment which is what is passed
|
|
||||||
# to the `call` method of each action. This environment contains
|
|
||||||
# some helper methods for accessing the environment as well
|
|
||||||
# as being a hash, to store any additional options.
|
|
||||||
class Environment < Util::HashWithIndifferentAccess
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
|
@ -23,7 +23,7 @@ module Vagrant
|
||||||
raise ArgumentError, "Argument to run must be a callable object or registered action." if !callable || !callable.respond_to?(:call)
|
raise ArgumentError, "Argument to run must be a callable object or registered action." if !callable || !callable.respond_to?(:call)
|
||||||
|
|
||||||
# Create the initial environment with the options given
|
# Create the initial environment with the options given
|
||||||
environment = Environment.new
|
environment = {}
|
||||||
environment.merge!(@globals)
|
environment.merge!(@globals)
|
||||||
environment.merge!(@lazy_globals.call) if @lazy_globals
|
environment.merge!(@lazy_globals.call) if @lazy_globals
|
||||||
environment.merge!(options || {})
|
environment.merge!(options || {})
|
||||||
|
|
|
@ -18,6 +18,17 @@ describe Vagrant::Action::Builtin::Call do
|
||||||
received.should == "value"
|
received.should == "value"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "should update the original env with any changes" do
|
||||||
|
callable = lambda { |env| }
|
||||||
|
next_step = lambda { |env| env[:inner] = true }
|
||||||
|
|
||||||
|
described_class.new(app, env, callable) do |_env, builder|
|
||||||
|
builder.use next_step
|
||||||
|
end.call(env)
|
||||||
|
|
||||||
|
env[:inner].should == true
|
||||||
|
end
|
||||||
|
|
||||||
it "should call the callable with the original environment" do
|
it "should call the callable with the original environment" do
|
||||||
received = nil
|
received = nil
|
||||||
callable = lambda { |env| received = env[:foo] }
|
callable = lambda { |env| received = env[:foo] }
|
||||||
|
|
Loading…
Reference in New Issue