Moved the resource name to a helper method in environment

This commit is contained in:
Mitchell Hashimoto 2010-08-26 20:22:20 -07:00
parent aaac5fbf1e
commit 6d15a1dd64
3 changed files with 23 additions and 3 deletions

View File

@ -100,6 +100,13 @@ module Vagrant
File.join(home_path, "boxes")
end
# Returns the name of the resource which this environment represents.
# The resource is the VM name if there is a VM it represents, otherwise
# it defaults to "vagrant"
def resource
vm_name || "vagrant"
end
# Returns the VMs associated with this environment.
def vms
@vms ||= {}
@ -238,7 +245,6 @@ module Vagrant
# references to logger won't throw nil exceptions, but by default
# the logger will just send the log data to a black hole.
def load_logger!
resource = vm_name || "vagrant"
@logger = Util::ResourceLogger.new(resource, self)
end

View File

@ -44,8 +44,7 @@ module Vagrant
protected
def format_message(message)
name = env.vm_name || "vagrant"
"[#{name}] #{message}"
"[#{env.resource}] #{message}"
end
def line_reset

View File

@ -128,6 +128,21 @@ class EnvironmentTest < Test::Unit::TestCase
end
end
context "resource" do
setup do
@env = mock_environment
end
should "return 'vagrant' as a default" do
assert_equal 'vagrant', @env.resource
end
should "return the VM name if it is specified" do
@env.stubs(:vm_name).returns("foo")
assert_equal "foo", @env.resource
end
end
context "primary VM helper" do
setup do
@env = mock_environment