From 3c3c9aedc93009e300795c56d5dc32baf8656b67 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Fri, 3 Sep 2010 09:35:07 -0700 Subject: [PATCH] Data store is a hash with indifferent access --- lib/vagrant/data_store.rb | 4 ++-- test/vagrant/data_store_test.rb | 8 ++++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/vagrant/data_store.rb b/lib/vagrant/data_store.rb index ce9ed7b00..c88f98c2e 100644 --- a/lib/vagrant/data_store.rb +++ b/lib/vagrant/data_store.rb @@ -5,7 +5,7 @@ module Vagrant # and `[]=`. If a key is set to `nil`, then it is removed from the # datastore. The data store is only updated on disk when {commit} # is called on the data store itself. - class DataStore < Hash + class DataStore < Util::HashWithIndifferentAccess attr_reader :file_path def initialize(file_path) @@ -13,7 +13,7 @@ module Vagrant return if !file_path File.open(file_path, "r") do |f| - merge!(JSON.parse(f.read, :symbolize_names => true)) + merge!(JSON.parse(f.read)) end rescue Errno::ENOENT clear diff --git a/test/vagrant/data_store_test.rb b/test/vagrant/data_store_test.rb index 59860ad47..b9a0d59e6 100644 --- a/test/vagrant/data_store_test.rb +++ b/test/vagrant/data_store_test.rb @@ -14,18 +14,22 @@ class DataStoreTest < Test::Unit::TestCase File.delete(@db_file) end + should "be a hash with indifferent access" do + assert @instance.is_a?(Vagrant::Util::HashWithIndifferentAccess) + end + should "just be an empty hash if file doesn't exist" do assert @klass.new("NEvERNENVENRNE").empty? end should "read the data" do - assert_equal @initial_data[:foo], @instance["foo"] + assert_equal @initial_data["foo"], @instance[:foo] end should "write the data, but not save it right away" do @instance[:foo] = "changed" assert_equal "changed", @instance[:foo] - assert_equal @initial_data[:foo], @klass.new(@db_file)["foo"] + assert_equal @initial_data["foo"], @klass.new(@db_file)["foo"] end should "write the data if commit is called" do