Moved the resource name to a helper method in environment
This commit is contained in:
parent
aaac5fbf1e
commit
6d15a1dd64
|
@ -100,6 +100,13 @@ module Vagrant
|
||||||
File.join(home_path, "boxes")
|
File.join(home_path, "boxes")
|
||||||
end
|
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.
|
# Returns the VMs associated with this environment.
|
||||||
def vms
|
def vms
|
||||||
@vms ||= {}
|
@vms ||= {}
|
||||||
|
@ -238,7 +245,6 @@ module Vagrant
|
||||||
# references to logger won't throw nil exceptions, but by default
|
# references to logger won't throw nil exceptions, but by default
|
||||||
# the logger will just send the log data to a black hole.
|
# the logger will just send the log data to a black hole.
|
||||||
def load_logger!
|
def load_logger!
|
||||||
resource = vm_name || "vagrant"
|
|
||||||
@logger = Util::ResourceLogger.new(resource, self)
|
@logger = Util::ResourceLogger.new(resource, self)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -44,8 +44,7 @@ module Vagrant
|
||||||
protected
|
protected
|
||||||
|
|
||||||
def format_message(message)
|
def format_message(message)
|
||||||
name = env.vm_name || "vagrant"
|
"[#{env.resource}] #{message}"
|
||||||
"[#{name}] #{message}"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def line_reset
|
def line_reset
|
||||||
|
|
|
@ -128,6 +128,21 @@ class EnvironmentTest < Test::Unit::TestCase
|
||||||
end
|
end
|
||||||
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
|
context "primary VM helper" do
|
||||||
setup do
|
setup do
|
||||||
@env = mock_environment
|
@env = mock_environment
|
||||||
|
|
Loading…
Reference in New Issue