Top config class is now available in all `Vagrant::Config::Base` subclasses. Useful for validation.

This commit is contained in:
Mitchell Hashimoto 2010-09-30 00:50:17 -07:00
parent c0e3047af7
commit 588ead6e45
5 changed files with 19 additions and 1 deletions

View File

@ -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]

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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)