Load the host on demand in the environment

This commit is contained in:
Mitchell Hashimoto 2010-09-03 00:48:38 -07:00
parent 01df63ef6e
commit 0f70812142
3 changed files with 20 additions and 21 deletions

View File

@ -16,7 +16,6 @@ module Vagrant
attr_reader :cwd
attr_reader :root_path
attr_reader :config
attr_reader :host
attr_reader :box
attr_accessor :vm
attr_writer :ui
@ -134,6 +133,11 @@ module Vagrant
end
end
# Returns the host object associated with this environment.
def host
@host ||= Hosts::Base.load(self, config.vagrant.host)
end
# Returns the {Action} class for this environment which allows actions
# to be executed (middleware chains) in the context of this environment.
def actions
@ -178,7 +182,6 @@ module Vagrant
load_root_path!
load_config!
load_home_directory!
load_host!
load_box!
load_config!
self.class.check_virtualbox!
@ -265,11 +268,6 @@ module Vagrant
end
end
# Loads the host class for this environment.
def load_host!
@host = Hosts::Base.load(self, config.vagrant.host)
end
# Loads the specified box for this environment.
def load_box!
return unless root_path

View File

@ -18,6 +18,7 @@ class NFSHelpersVMActionTest < Test::Unit::TestCase
end
should "not do anything if host is nil" do
@env.env.stubs(:host).returns(nil)
assert_nothing_raised { @instance.clear_nfs_exports(@env) }
end
end

View File

@ -234,6 +234,20 @@ class EnvironmentTest < Test::Unit::TestCase
end
end
context "accessing host" do
setup do
@env = mock_environment
end
should "load the host once" do
result = mock("result")
Vagrant::Hosts::Base.expects(:load).with(@env, @env.config.vagrant.host).once.returns(result)
assert_equal result, @env.host
assert_equal result, @env.host
assert_equal result, @env.host
end
end
context "accessing actions" do
setup do
@env = mock_environment
@ -301,7 +315,6 @@ class EnvironmentTest < Test::Unit::TestCase
@env.expects(:load_root_path!).once.in_sequence(call_seq)
@env.expects(:load_config!).once.in_sequence(call_seq)
@env.expects(:load_home_directory!).once.in_sequence(call_seq)
@env.expects(:load_host!).once.in_sequence(call_seq)
@env.expects(:load_box!).once.in_sequence(call_seq)
@env.expects(:load_config!).once.in_sequence(call_seq)
@klass.expects(:check_virtualbox!).once.in_sequence(call_seq)
@ -505,19 +518,6 @@ class EnvironmentTest < Test::Unit::TestCase
end
end
context "loading host" do
setup do
@env = mock_environment
end
should "load the host by calling the load method on Host::Base" do
result = mock("result")
Vagrant::Hosts::Base.expects(:load).with(@env, @env.config.vagrant.host).once.returns(result)
@env.load_host!
assert_equal result, @env.host
end
end
context "loading box" do
setup do
@box = mock("box")