diff --git a/CHANGELOG.md b/CHANGELOG.md index 7be5de0e4..1c996dcc4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ ## 0.6.4 (unreleased) + - Top config class is now available in all `Vagrant::Config::Base` + subclasses, which is useful for config validation. - Subcommand help shows proper full command in task listing. [GH-168] - SSH gives error message if `ssh` binary is not found. [GH-161] - SSH gives proper error message if VM is not running. [GH-167] diff --git a/lib/vagrant/config.rb b/lib/vagrant/config.rb index 2acf68c9b..b9748748d 100644 --- a/lib/vagrant/config.rb +++ b/lib/vagrant/config.rb @@ -137,6 +137,7 @@ module Vagrant self.class.configures_list.each do |key, klass| config = klass.new config.env = env + config.top = self instance_variable_set("@#{key}".to_sym, config) end diff --git a/lib/vagrant/config/base.rb b/lib/vagrant/config/base.rb index 57e10f796..2f90ffff6 100644 --- a/lib/vagrant/config/base.rb +++ b/lib/vagrant/config/base.rb @@ -4,8 +4,12 @@ module Vagrant # basic things such as the environment instance variable which all # config classes need as well as a basic `to_json` implementation. class Base + # {Environment} that this config belongs to attr_accessor :env + # {Top} of this configuration stack + attr_accessor :top + # Registers a subclass with the Vagrant configuration system so # that it can then be used in Vagrantfiles. # @@ -58,7 +62,7 @@ module Vagrant # Returns the instance variables as a hash of key-value pairs. def instance_variables_hash instance_variables.inject({}) do |acc, iv| - acc[iv.to_s[1..-1]] = instance_variable_get(iv) unless iv.to_sym == :@env + acc[iv.to_s[1..-1]] = instance_variable_get(iv) unless [:@env, :@top].include?(iv.to_sym) acc end end diff --git a/test/vagrant/config/base_test.rb b/test/vagrant/config/base_test.rb index 858238c17..ee184a030 100644 --- a/test/vagrant/config/base_test.rb +++ b/test/vagrant/config/base_test.rb @@ -47,6 +47,12 @@ class ConfigBaseTest < Test::Unit::TestCase hash = @base.instance_variables_hash assert !hash.has_key?(:env) end + + should "not include top in the JSON hash" do + @base.top = "FOO" + hash = @base.instance_variables_hash + assert !hash.has_key?(:top) + end end end end diff --git a/test/vagrant/config_test.rb b/test/vagrant/config_test.rb index 37dd3f628..c57466fd8 100644 --- a/test/vagrant/config_test.rb +++ b/test/vagrant/config_test.rb @@ -167,6 +167,10 @@ class ConfigTest < Test::Unit::TestCase klass = mock("klass#{i}") instance = mock("instance#{i}") instance.expects(:env=).with(env) + instance.expects(:top=).with() do |top| + assert top.is_a?(@klass::Top) + true + end klass.expects(:new).returns(instance) @configures_list[key] = klass end @@ -179,6 +183,7 @@ class ConfigTest < Test::Unit::TestCase klass = mock("klass") instance = mock("instance") instance.stubs(:env=) + instance.stubs(:top=) klass.expects(:new).returns(instance) @klass::Top.configures(key, klass)