diff --git a/lib/vagrant/config.rb b/lib/vagrant/config.rb index 94740d76e..54b76766c 100644 --- a/lib/vagrant/config.rb +++ b/lib/vagrant/config.rb @@ -20,10 +20,6 @@ module Vagrant config(env) end - def configures(key, klass) - config.class.configures(key, klass) - end - def config(env=nil) @@config ||= Config::Top.new(env) end diff --git a/lib/vagrant/config/base.rb b/lib/vagrant/config/base.rb index 1bb997926..57e10f796 100644 --- a/lib/vagrant/config/base.rb +++ b/lib/vagrant/config/base.rb @@ -6,6 +6,16 @@ module Vagrant class Base attr_accessor :env + # Registers a subclass with the Vagrant configuration system so + # that it can then be used in Vagrantfiles. + # + # @param [Symbol] accessor The accessor on the main config object + # that is used to access the configuration class. + # + def self.configures(accessor, klass=self) + Top.configures(accessor, klass) + end + # Loads configuration values from JSON back into the proper # configuration classes. By default, this is done by simply # iterating over all values in the JSON hash and assigning them diff --git a/lib/vagrant/config/nfs.rb b/lib/vagrant/config/nfs.rb index 68a222f9c..e3a37c236 100644 --- a/lib/vagrant/config/nfs.rb +++ b/lib/vagrant/config/nfs.rb @@ -1,7 +1,7 @@ module Vagrant class Config class NFSConfig < Base - Config.configures :nfs, self + configures :nfs attr_accessor :map_uid attr_accessor :map_gid diff --git a/lib/vagrant/config/package.rb b/lib/vagrant/config/package.rb index 2833ed641..90355a080 100644 --- a/lib/vagrant/config/package.rb +++ b/lib/vagrant/config/package.rb @@ -1,7 +1,7 @@ module Vagrant class Config class PackageConfig < Base - Config.configures :package, self + configures :package attr_accessor :name end diff --git a/lib/vagrant/config/ssh.rb b/lib/vagrant/config/ssh.rb index fc0a3f3d3..1a9a968ea 100644 --- a/lib/vagrant/config/ssh.rb +++ b/lib/vagrant/config/ssh.rb @@ -1,7 +1,7 @@ module Vagrant class Config class SSHConfig < Base - Config.configures :ssh, self + configures :ssh attr_accessor :username attr_accessor :host diff --git a/lib/vagrant/config/vagrant.rb b/lib/vagrant/config/vagrant.rb index 5fa56bf3d..c518fd811 100644 --- a/lib/vagrant/config/vagrant.rb +++ b/lib/vagrant/config/vagrant.rb @@ -1,7 +1,7 @@ module Vagrant class Config class VagrantConfig < Base - Config.configures :vagrant, self + configures :vagrant attr_accessor :dotfile_name attr_accessor :log_output diff --git a/lib/vagrant/config/vm.rb b/lib/vagrant/config/vm.rb index dd73adcd0..814534378 100644 --- a/lib/vagrant/config/vm.rb +++ b/lib/vagrant/config/vm.rb @@ -1,7 +1,7 @@ module Vagrant class Config class VMConfig < Base - Config.configures :vm, self + configures :vm include Util::StackedProcRunner diff --git a/lib/vagrant/provisioners/chef.rb b/lib/vagrant/provisioners/chef.rb index 4a0ab4947..d72553ee9 100644 --- a/lib/vagrant/provisioners/chef.rb +++ b/lib/vagrant/provisioners/chef.rb @@ -62,6 +62,8 @@ module Vagrant class Chef < Base # This is the configuration which is available through `config.chef` class ChefConfig < Vagrant::Config::Base + configures :chef + # Chef server specific config attr_accessor :chef_server_url attr_accessor :validation_key_path @@ -124,9 +126,6 @@ module Vagrant result end end - - # Tell the Vagrant configure class about our custom configuration - Config.configures :chef, ChefConfig end end end diff --git a/lib/vagrant/systems/linux.rb b/lib/vagrant/systems/linux.rb index 70c8a43b2..a05ebc374 100644 --- a/lib/vagrant/systems/linux.rb +++ b/lib/vagrant/systems/linux.rb @@ -13,7 +13,7 @@ module Vagrant # generally, Vagrant tries to make almost every aspect of its execution # configurable, and this assists that goal. class LinuxConfig < Vagrant::Config::Base - Config.configures :linux, self + configures :linux attr_accessor :halt_timeout attr_accessor :halt_check_interval diff --git a/lib/vagrant/systems/solaris.rb b/lib/vagrant/systems/solaris.rb index 9ee45370f..c4a08905e 100644 --- a/lib/vagrant/systems/solaris.rb +++ b/lib/vagrant/systems/solaris.rb @@ -9,7 +9,7 @@ module Vagrant # generally, Vagrant tries to make almost every aspect of its execution # configurable, and this assists that goal. class SolarisConfig < Vagrant::Config::Base - Config.configures :solaris, self + configures :solaris attr_accessor :halt_timeout attr_accessor :halt_check_interval diff --git a/test/vagrant/config/base_test.rb b/test/vagrant/config/base_test.rb index 44cc69aff..858238c17 100644 --- a/test/vagrant/config/base_test.rb +++ b/test/vagrant/config/base_test.rb @@ -2,36 +2,51 @@ require "test_helper" class ConfigBaseTest < Test::Unit::TestCase setup do - @base = Vagrant::Config::Base.new + @klass = Vagrant::Config::Base end - should "return a hash of instance variables" do - data = { "foo" => "bar", "bar" => "baz" } - - data.each do |iv, value| - @base.instance_variable_set("@#{iv}".to_sym, value) - end - - result = @base.instance_variables_hash - assert_equal data.length, result.length - - data.each do |iv, value| - assert_equal value, result[iv] + context "class methods" do + should "enable configuration with proper accessor" do + klass = Class.new(@klass) + acc = :foo + Vagrant::Config::Top.expects(:configures).with(acc, klass) + klass.configures(acc) end end - context "converting to JSON" do - should "include magic `json_class`" do - @iv_hash = { "foo" => "bar" } - @base.expects(:instance_variables_hash).returns(@iv_hash) - @json = { 'json_class' => @base.class.name }.merge(@iv_hash).to_json - assert_equal @json, @base.to_json + context "instance methods" do + setup do + @base = @klass.new end - should "not include env in the JSON hash" do - @base.env = "FOO" - hash = @base.instance_variables_hash - assert !hash.has_key?(:env) + should "return a hash of instance variables" do + data = { "foo" => "bar", "bar" => "baz" } + + data.each do |iv, value| + @base.instance_variable_set("@#{iv}".to_sym, value) + end + + result = @base.instance_variables_hash + assert_equal data.length, result.length + + data.each do |iv, value| + assert_equal value, result[iv] + end + end + + context "converting to JSON" do + should "include magic `json_class`" do + @iv_hash = { "foo" => "bar" } + @base.expects(:instance_variables_hash).returns(@iv_hash) + @json = { 'json_class' => @base.class.name }.merge(@iv_hash).to_json + assert_equal @json, @base.to_json + end + + should "not include env in the JSON hash" do + @base.env = "FOO" + hash = @base.instance_variables_hash + assert !hash.has_key?(:env) + end end end end diff --git a/test/vagrant/config_test.rb b/test/vagrant/config_test.rb index f04e223c7..e8276acb5 100644 --- a/test/vagrant/config_test.rb +++ b/test/vagrant/config_test.rb @@ -72,15 +72,6 @@ class ConfigTest < Test::Unit::TestCase end end - context "adding configures" do - should "forward the method to the Top class" do - key = mock("key") - klass = mock("klass") - @klass::Top.expects(:configures).with(key, klass) - @klass.configures(key, klass) - end - end - context "resetting" do setup do @klass::Top.any_instance.stubs(:validate!)