Top config class is now available in all `Vagrant::Config::Base` subclasses. Useful for validation.
This commit is contained in:
parent
c0e3047af7
commit
588ead6e45
|
@ -1,5 +1,7 @@
|
||||||
## 0.6.4 (unreleased)
|
## 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]
|
- 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 error message if `ssh` binary is not found. [GH-161]
|
||||||
- SSH gives proper error message if VM is not running. [GH-167]
|
- SSH gives proper error message if VM is not running. [GH-167]
|
||||||
|
|
|
@ -137,6 +137,7 @@ module Vagrant
|
||||||
self.class.configures_list.each do |key, klass|
|
self.class.configures_list.each do |key, klass|
|
||||||
config = klass.new
|
config = klass.new
|
||||||
config.env = env
|
config.env = env
|
||||||
|
config.top = self
|
||||||
instance_variable_set("@#{key}".to_sym, config)
|
instance_variable_set("@#{key}".to_sym, config)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -4,8 +4,12 @@ module Vagrant
|
||||||
# basic things such as the environment instance variable which all
|
# basic things such as the environment instance variable which all
|
||||||
# config classes need as well as a basic `to_json` implementation.
|
# config classes need as well as a basic `to_json` implementation.
|
||||||
class Base
|
class Base
|
||||||
|
# {Environment} that this config belongs to
|
||||||
attr_accessor :env
|
attr_accessor :env
|
||||||
|
|
||||||
|
# {Top} of this configuration stack
|
||||||
|
attr_accessor :top
|
||||||
|
|
||||||
# Registers a subclass with the Vagrant configuration system so
|
# Registers a subclass with the Vagrant configuration system so
|
||||||
# that it can then be used in Vagrantfiles.
|
# 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.
|
# Returns the instance variables as a hash of key-value pairs.
|
||||||
def instance_variables_hash
|
def instance_variables_hash
|
||||||
instance_variables.inject({}) do |acc, iv|
|
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
|
acc
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -47,6 +47,12 @@ class ConfigBaseTest < Test::Unit::TestCase
|
||||||
hash = @base.instance_variables_hash
|
hash = @base.instance_variables_hash
|
||||||
assert !hash.has_key?(:env)
|
assert !hash.has_key?(:env)
|
||||||
end
|
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
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -167,6 +167,10 @@ class ConfigTest < Test::Unit::TestCase
|
||||||
klass = mock("klass#{i}")
|
klass = mock("klass#{i}")
|
||||||
instance = mock("instance#{i}")
|
instance = mock("instance#{i}")
|
||||||
instance.expects(:env=).with(env)
|
instance.expects(:env=).with(env)
|
||||||
|
instance.expects(:top=).with() do |top|
|
||||||
|
assert top.is_a?(@klass::Top)
|
||||||
|
true
|
||||||
|
end
|
||||||
klass.expects(:new).returns(instance)
|
klass.expects(:new).returns(instance)
|
||||||
@configures_list[key] = klass
|
@configures_list[key] = klass
|
||||||
end
|
end
|
||||||
|
@ -179,6 +183,7 @@ class ConfigTest < Test::Unit::TestCase
|
||||||
klass = mock("klass")
|
klass = mock("klass")
|
||||||
instance = mock("instance")
|
instance = mock("instance")
|
||||||
instance.stubs(:env=)
|
instance.stubs(:env=)
|
||||||
|
instance.stubs(:top=)
|
||||||
klass.expects(:new).returns(instance)
|
klass.expects(:new).returns(instance)
|
||||||
@klass::Top.configures(key, klass)
|
@klass::Top.configures(key, klass)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue