Upgrade all other default configurations to V2

This commit is contained in:
Mitchell Hashimoto 2012-12-23 16:14:41 -08:00
parent bf53abca76
commit 3808ea377f
6 changed files with 66 additions and 8 deletions

View File

@ -5,6 +5,13 @@ module Vagrant
# V1. Any configuration key plugins for V1 should inherit from this
# class.
class Config
# This constant represents an unset value. This is useful so it is
# possible to know the difference between a configuration value that
# was never set, and a value that is nil (explicitly). Best practice
# is to initialize all variables to this value, then the {#merge}
# method below will "just work" in many cases.
UNSET_VALUE = Object.new
# This is called as a last-minute hook that allows the configuration
# object to finalize itself before it will be put into use. This is
# a useful place to do some defaults in the case the user didn't

View File

@ -5,6 +5,16 @@ module VagrantPlugins
class NFSConfig < Vagrant.plugin("1", :config)
attr_accessor :map_uid
attr_accessor :map_gid
def initialize
@map_uid = UNSET_VALUE
@map_gid = UNSET_VALUE
end
def upgrade(new)
new.nfs.map_uid = @map_uid if @map_uid != UNSET_VALUE
new.nfs.map_gid = @map_gid if @map_gid != UNSET_VALUE
end
end
end
end

View File

@ -4,6 +4,14 @@ module VagrantPlugins
module Kernel_V1
class PackageConfig < Vagrant.plugin("1", :config)
attr_accessor :name
def initialize
@name = UNSET_VALUE
end
def upgrade(new)
new.package.name = @name if @name != UNSET_VALUE
end
end
end
end

View File

@ -15,15 +15,32 @@ module VagrantPlugins
attr_accessor :forward_x11
attr_accessor :shell
def validate(env, errors)
[:username, :host, :max_tries, :timeout].each do |field|
value = instance_variable_get("@#{field}".to_sym)
errors.add(I18n.t("vagrant.config.common.error_empty", :field => field)) if !value
def initialize
@username = UNSET_VALUE
@password = UNSET_VALUE
@host = UNSET_VALUE
@port = UNSET_VALUE
@guest_port = UNSET_VALUE
@max_tries = UNSET_VALUE
@timeout = UNSET_VALUE
@private_key_path = UNSET_VALUE
@forward_agent = UNSET_VALUE
@forward_x11 = UNSET_VALUE
@shell = UNSET_VALUE
end
if private_key_path && !File.file?(File.expand_path(private_key_path, env.root_path))
errors.add(I18n.t("vagrant.config.ssh.private_key_missing", :path => private_key_path))
end
def upgrade(new)
new.ssh.username = @username if @username != UNSET_VALUE
new.ssh.password = @password if @password != UNSET_VALUE
new.ssh.host = @host if @host != UNSET_VALUE
new.ssh.port = @port if @port != UNSET_VALUE
new.ssh.guest_port = @guest_port if @guest_port != UNSET_VALUE
new.ssh.max_tries = @max_tries if @max_tries != UNSET_VALUE
new.ssh.timeout = @timeout if @timeout != UNSET_VALUE
new.ssh.private_key_path = @private_key_path if @private_key_path != UNSET_VALUE
new.ssh.forward_agent = @forward_agent if @forward_agent != UNSET_VALUE
new.ssh.forward_x11 = @forward_x11 if @forward_x11 != UNSET_VALUE
new.ssh.shell = @shell if @shell != UNSET_VALUE
end
end
end

View File

@ -5,6 +5,16 @@ module VagrantPlugins
class VagrantConfig < Vagrant.plugin("1", :config)
attr_accessor :dotfile_name
attr_accessor :host
def initialize
@dotfile_name = UNSET_VALUE
@host = UNSET_VALUE
end
def upgrade(new)
new.vagrant.dotfile_name = @dotfile_name if @dotfile_name != UNSET_VALUE
new.vagrant.host = @host if @host != UNSET_VALUE
end
end
end
end

View File

@ -10,6 +10,12 @@ describe Vagrant::Plugin::V1::Config do
end
end
it "has an UNSET_VALUE constant" do
value = described_class.const_get("UNSET_VALUE")
value.should be_kind_of Object
value.should eql(described_class.const_get("UNSET_VALUE"))
end
describe "merging" do
it "should merge by default by simply copying each instance variable" do
one = foo_class.new