Call now only yields the environment
This commit is contained in:
parent
118377e6f0
commit
e5f250121a
|
@ -3,17 +3,16 @@ module Vagrant
|
|||
module Builtin
|
||||
# This middleware class allows a sort of "conditional" run within
|
||||
# a single middlware sequence. It takes another middleware runnable,
|
||||
# runs it with the same environment, then yields the result to a block,
|
||||
# runs it with the same environment, then yields the resulting env to a block,
|
||||
# allowing that block to determine the next course of action in the
|
||||
# middleware sequence.
|
||||
#
|
||||
# The first argument to this middleware sequence is anywhere middleware
|
||||
# runnable, whether it be a class, lambda, or something else that
|
||||
# responds to `call`. This middleware runnable is run with the same
|
||||
# environment as this class. The "result" of the run is expected to be
|
||||
# placed in `env[:result]`.
|
||||
# environment as this class.
|
||||
#
|
||||
# After running, {Call} takes `env[:result]` and yields it to a block
|
||||
# After running, {Call} takes the environment and yields it to a block
|
||||
# given to initialize the class, along with an instance of {Builder}.
|
||||
# The result is used to build up a new sequence on the given builder.
|
||||
# This builder is then run.
|
||||
|
@ -40,7 +39,7 @@ module Vagrant
|
|||
|
||||
# Build our new builder based on the result
|
||||
builder = Builder.new
|
||||
@block.call(new_env, new_env[:result], builder)
|
||||
@block.call(new_env, builder)
|
||||
|
||||
# Run the result with our new environment
|
||||
final_env = runner.run(builder, new_env)
|
||||
|
|
|
@ -16,25 +16,25 @@ module VagrantPlugins
|
|||
def self.action_destroy
|
||||
Vagrant::Action::Builder.new.tap do |b|
|
||||
b.use CheckVirtualbox
|
||||
b.use Call, Created do |env, created, b2|
|
||||
if created
|
||||
b.use Call, Created do |env1, b2|
|
||||
if env1[:result]
|
||||
# If the VM is created, then we confirm that we want to
|
||||
# destroy it.
|
||||
message = I18n.t("vagrant.commands.destroy.confirmation",
|
||||
:name => env[:machine].name)
|
||||
confirm = Vagrant::Action::Builder.build(Confirm, message)
|
||||
|
||||
b2.use Call, confirm do |_env, confirmed, b3|
|
||||
if confirmed
|
||||
b2.use Call, confirm do |env2, b3|
|
||||
if env2[:result]
|
||||
b3.use Vagrant::Action::General::Validate
|
||||
b3.use CheckAccessible
|
||||
else
|
||||
env[:ui].info I18n.t("vagrant.commands.destroy.will_not_destroy",
|
||||
env2[:ui].info I18n.t("vagrant.commands.destroy.will_not_destroy",
|
||||
:name => env[:machine.name])
|
||||
end
|
||||
end
|
||||
else
|
||||
env[:ui].info I18n.t("vagrant.commands.common.vm_not_created")
|
||||
env1[:ui].info I18n.t("vagrant.commands.common.vm_not_created")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -4,36 +4,25 @@ describe Vagrant::Action::Builtin::Call do
|
|||
let(:app) { lambda { |env| } }
|
||||
let(:env) { {} }
|
||||
|
||||
it "should yield the result to the block" do
|
||||
it "should yield the env to the block" do
|
||||
received = nil
|
||||
|
||||
callable = lambda do |env|
|
||||
env[:result] = "value"
|
||||
end
|
||||
|
||||
described_class.new(app, env, callable) do |_env, result, builder|
|
||||
received = result
|
||||
described_class.new(app, env, callable) do |env, builder|
|
||||
received = env[:result]
|
||||
end.call({})
|
||||
|
||||
received.should == "value"
|
||||
end
|
||||
|
||||
it "should give a nil result if no result is given" do
|
||||
received = 42
|
||||
callable = lambda { |env| }
|
||||
|
||||
described_class.new(app, env, callable) do |_env, result, builder|
|
||||
received = result
|
||||
end.call({})
|
||||
|
||||
received.should be_nil
|
||||
end
|
||||
|
||||
it "should call the callable with the original environment" do
|
||||
received = nil
|
||||
callable = lambda { |env| received = env[:foo] }
|
||||
|
||||
described_class.new(app, env, callable) do |_env, result, builder|
|
||||
described_class.new(app, env, callable) do |_env, _builder|
|
||||
# Nothing.
|
||||
end.call({ :foo => :bar })
|
||||
|
||||
|
@ -45,7 +34,7 @@ describe Vagrant::Action::Builtin::Call do
|
|||
callable = lambda { |env| }
|
||||
next_step = lambda { |env| received = "value" }
|
||||
|
||||
described_class.new(app, env, callable) do |_env, result, builder|
|
||||
described_class.new(app, env, callable) do |_env, builder|
|
||||
builder.use next_step
|
||||
end.call({})
|
||||
|
||||
|
@ -57,21 +46,10 @@ describe Vagrant::Action::Builtin::Call do
|
|||
callable = lambda { |env| }
|
||||
next_step = lambda { |env| received = env[:foo] }
|
||||
|
||||
described_class.new(app, env, callable) do |_env, result, builder|
|
||||
described_class.new(app, env, callable) do |_env, builder|
|
||||
builder.use next_step
|
||||
end.call({ :foo => :bar })
|
||||
|
||||
received.should == :bar
|
||||
end
|
||||
|
||||
it "should yield the environment" do
|
||||
received = nil
|
||||
callable = lambda { |env| env[:foo] = "value" }
|
||||
|
||||
described_class.new(app, env, callable) do |env, _result, _builder|
|
||||
received = env[:foo]
|
||||
end.call({})
|
||||
|
||||
received.should == "value"
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue