Vagrant.configure is now how configuration is done in Vagrantfiles (previously it was Vagrant::Config.run). This function takes a single argument which is the version of configuration to use. Various internals were updated for this new versioned configuration. Note that multiple versions of configuration aren't yet used so aren't fully supported by Vagrant, but the foundation is being set here.
62 lines
2.2 KiB
Ruby
62 lines
2.2 KiB
Ruby
require "vagrant/registry"
|
|
|
|
module Vagrant
|
|
module Config
|
|
autoload :Base, 'vagrant/config/base'
|
|
autoload :Container, 'vagrant/config/container'
|
|
autoload :ErrorRecorder, 'vagrant/config/error_recorder'
|
|
autoload :Loader, 'vagrant/config/loader'
|
|
autoload :VersionBase, 'vagrant/config/version_base'
|
|
|
|
autoload :V1, 'vagrant/config/v1'
|
|
|
|
# This is a mutex used to guarantee that only one thread can load
|
|
# procs at any given time.
|
|
CONFIGURE_MUTEX = Mutex.new
|
|
|
|
# This is the registry which keeps track of what configuration
|
|
# versions are available, mapped by the version string used in
|
|
# `Vagrant.configure` calls.
|
|
VERSIONS = Registry.new
|
|
VERSIONS.register("1") { V1 }
|
|
|
|
# This is the order of versions. This is used by the loader to figure out
|
|
# how to "upgrade" versions up to the desired (current) version. The
|
|
# current version is always considered to be the last version in this
|
|
# list.
|
|
VERSIONS_ORDER = ["1"]
|
|
|
|
# This is the method which is called by all Vagrantfiles to configure Vagrant.
|
|
# This method expects a block which accepts a single argument representing
|
|
# an instance of the {Config::Top} class.
|
|
#
|
|
# Note that the block is not run immediately. Instead, it's proc is stored
|
|
# away for execution later.
|
|
def self.run(version="1", &block)
|
|
# Store it for later
|
|
@last_procs ||= []
|
|
@last_procs << [version, block]
|
|
end
|
|
|
|
# This is a method which will yield to a block and will capture all
|
|
# ``Vagrant.configure`` calls, returning an array of `Proc`s.
|
|
#
|
|
# Wrapping this around anytime you call code which loads configurations
|
|
# will force a mutex so that procs never get mixed up. This keeps
|
|
# the configuration loading part of Vagrant thread-safe.
|
|
def self.capture_configures
|
|
CONFIGURE_MUTEX.synchronize do
|
|
# Reset the last procs so that we start fresh
|
|
@last_procs = []
|
|
|
|
# Yield to allow the caller to do whatever loading needed
|
|
yield
|
|
|
|
# Return the last procs we've seen while still in the mutex,
|
|
# knowing we're safe.
|
|
return @last_procs
|
|
end
|
|
end
|
|
end
|
|
end
|