Config loader no longer assumes latest version for procs.

Previously, all procs were assumed to just be the current version. This
is certainly not going to be true always so now the version number of
the configuration must be explicit if you're assigning a proc to the
configuration loader.
This commit is contained in:
Mitchell Hashimoto 2012-06-23 12:06:54 -07:00
parent b3db82e516
commit 7e19d6849b
4 changed files with 48 additions and 23 deletions

View File

@ -114,30 +114,42 @@ module Vagrant
# the configuration object and are expected to mutate this # the configuration object and are expected to mutate this
# configuration object. # configuration object.
def procs_for_source(source) def procs_for_source(source)
# If the source is just a proc, we assume it is for the latest # Convert all pathnames to strings so we just have their path
# version of the configuration. This may be an ill assumption, source = source.to_s if source.is_a?(Pathname)
# but it made building the initial version of multi-versioned
# configuration easy to support the old sub-VM stuff.
return [[@version_order.last, source]] if source.is_a?(Proc)
# Assume all string sources are actually pathnames if source.is_a?(Array)
source = Pathname.new(source) if source.is_a?(String) # An array must be formatted as [version, proc], so verify
# that and then return it
raise ArgumentError, "String source must have format [version, proc]" if source.length != 2
if source.is_a?(Pathname) # Return it as an array since we're expected to return an array
@logger.debug("Load procs for pathname: #{source.inspect}") # of [version, proc] pairs, but an array source only has one.
return [source]
begin elsif source.is_a?(String)
return Config.capture_configures do # Strings are considered paths, so load them
Kernel.load source return procs_for_path(source)
end else
rescue SyntaxError => e raise ArgumentError, "Unknown configuration source: #{source.inspect}"
# Report syntax errors in a nice way.
raise Errors::VagrantfileSyntaxError, :file => e.message
end
end end
raise Exception, "Unknown configuration source: #{source.inspect}"
end end
# This returns an array of `Proc` objects for the given path source.
#
# @param [String] path Path to the file which contains the proper
# `Vagrant.configure` calls.
# @return [Array<Proc>]
def procs_for_path(path)
@logger.debug("Load procs for pathname: #{path}")
begin
return Config.capture_configures do
Kernel.load path
end
rescue SyntaxError => e
# Report syntax errors in a nice way.
raise Errors::VagrantfileSyntaxError, :file => e.message
end
end
end end
end end
end end

View File

@ -395,7 +395,7 @@ module Vagrant
if subvm if subvm
# We have subvm configuration, so set that up as well. # We have subvm configuration, so set that up as well.
config_loader.set(:vm, subvm.proc_stack) config_loader.set(:vm, subvm.config_procs)
end end
# We activate plugins here because the files which we're loading # We activate plugins here because the files which we're loading

View File

@ -11,6 +11,16 @@ module VagrantPlugins
def initialize def initialize
@options = {} @options = {}
end end
# This returns an array of the procs to configure this VM, with
# the proper version pre-pended for the configuration loader.
#
# @return [Array]
def config_procs
proc_stack.map do |proc|
["1", proc]
end
end
end end
end end
end end

View File

@ -5,6 +5,9 @@ require "vagrant/registry"
describe Vagrant::Config::Loader do describe Vagrant::Config::Loader do
include_context "unit" include_context "unit"
# This is the current version of configuration for the tests.
let(:current_version) { version_order.last }
# This is just a dummy implementation of a configuraiton loader which # This is just a dummy implementation of a configuraiton loader which
# simply acts on hashes. # simply acts on hashes.
let(:test_loader) do let(:test_loader) do
@ -46,7 +49,7 @@ describe Vagrant::Config::Loader do
end end
instance.load_order = [:proc] instance.load_order = [:proc]
instance.set(:proc, proc) instance.set(:proc, [[current_version, proc]])
config = instance.load config = instance.load
config[:foo].should == "yep" config[:foo].should == "yep"
@ -60,7 +63,7 @@ describe Vagrant::Config::Loader do
end end
instance.load_order = [:proc] instance.load_order = [:proc]
instance.set(:proc, proc) instance.set(:proc, [[current_version, proc]])
5.times do 5.times do
result = instance.load result = instance.load