Added global data hash to environment. "system"-wide data bag for vagrant

This commit is contained in:
Mitchell Hashimoto 2010-09-03 00:21:57 -07:00
parent d65194d66e
commit f72979df79
2 changed files with 32 additions and 0 deletions

View File

@ -145,6 +145,16 @@ module Vagrant
end
end
# Loads on initial access and reads data from the global data store.
# The global data store is global to Vagrant everywhere (in every environment),
# so it can be used to store system-wide information. Note that "system-wide"
# typically means "for this user" since the location of the global data
# store is in the home directory.
def global_data
return parent.global_data if parent
@global_data ||= DataStore.new(File.expand_path("global_data.json", home_path))
end
# Loads (on initial access) and reads data from the local data
# store. This file is always at the root path as the file "~/.vagrant"
# and contains a JSON dump of a hash. See {DataStore} for more

View File

@ -245,6 +245,28 @@ class EnvironmentTest < Test::Unit::TestCase
end
end
context "global data" do
setup do
@env = mock_environment
end
should "lazy load the data store only once" do
result = mock("result")
Vagrant::DataStore.expects(:new).with(File.expand_path("global_data.json", @env.home_path)).returns(result).once
assert_equal result, @env.global_data
assert_equal result, @env.global_data
assert_equal result, @env.global_data
end
should "return the parent's local data if a parent exists" do
@env.stubs(:parent).returns(mock_environment)
result = @env.parent.global_data
Vagrant::DataStore.expects(:new).never
assert_equal result, @env.global_data
end
end
context "loading logger" do
should "lazy load the logger only once" do
result = Vagrant::Util::ResourceLogger.new("vagrant", mock_environment)