Configuration loads. Lots of refactor to do still.
This commit is contained in:
parent
0b38802329
commit
15c56a1f4c
|
@ -1,17 +1,19 @@
|
||||||
require 'vagrant/config/base'
|
require 'vagrant/config/base'
|
||||||
require 'vagrant/config/loader'
|
require 'vagrant/config/loader'
|
||||||
# require 'vagrant/config/error_recorder'
|
require 'vagrant/config/error_recorder'
|
||||||
require 'vagrant/config/top'
|
require 'vagrant/config/top'
|
||||||
|
|
||||||
# # The built-in configuration classes
|
# # The built-in configuration classes
|
||||||
# require 'vagrant/config/vagrant'
|
require 'vagrant/config/vagrant'
|
||||||
# require 'vagrant/config/ssh'
|
require 'vagrant/config/ssh'
|
||||||
# require 'vagrant/config/nfs'
|
require 'vagrant/config/nfs'
|
||||||
# require 'vagrant/config/vm'
|
require 'vagrant/config/vm'
|
||||||
# require 'vagrant/config/package'
|
require 'vagrant/config/package'
|
||||||
|
|
||||||
module Vagrant
|
module Vagrant
|
||||||
module Config
|
module Config
|
||||||
|
autoload :Container, 'vagrant/config/container'
|
||||||
|
|
||||||
CONFIGURE_MUTEX = Mutex.new
|
CONFIGURE_MUTEX = Mutex.new
|
||||||
|
|
||||||
# This is the method which is called by all Vagrantfiles to configure Vagrant.
|
# This is the method which is called by all Vagrantfiles to configure Vagrant.
|
||||||
|
|
|
@ -0,0 +1,13 @@
|
||||||
|
module Vagrant
|
||||||
|
module Config
|
||||||
|
# Contains loaded configuration values and provides access to those
|
||||||
|
# values.
|
||||||
|
#
|
||||||
|
# This is the class returned when loading configuration and stores
|
||||||
|
# the completely loaded configuration values. This class is meant to
|
||||||
|
# be immutable.
|
||||||
|
class Container
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -1,5 +1,5 @@
|
||||||
module Vagrant
|
module Vagrant
|
||||||
class Config
|
module Config
|
||||||
# A class which is passed into the various {Base#validate} methods and
|
# A class which is passed into the various {Base#validate} methods and
|
||||||
# can be used as a helper to add error messages about a single config
|
# can be used as a helper to add error messages about a single config
|
||||||
# class.
|
# class.
|
||||||
|
|
|
@ -43,19 +43,28 @@ module Vagrant
|
||||||
# This loads the configured sources in the configured order and returns
|
# This loads the configured sources in the configured order and returns
|
||||||
# an actual configuration object that is ready to be used.
|
# an actual configuration object that is ready to be used.
|
||||||
def load
|
def load
|
||||||
|
@logger.debug("Loading configuration in order: #{@load_order.inspect}")
|
||||||
|
|
||||||
unknown_sources = @sources.keys - @load_order
|
unknown_sources = @sources.keys - @load_order
|
||||||
if !unknown_sources.empty?
|
if !unknown_sources.empty?
|
||||||
# TODO: Raise exception here perhaps.
|
# TODO: Raise exception here perhaps.
|
||||||
@logger.error("Unknown config sources: #{unknown_sources.inspect}")
|
@logger.error("Unknown config sources: #{unknown_sources.inspect}")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
top = Top.new
|
||||||
|
|
||||||
@load_order.each do |key|
|
@load_order.each do |key|
|
||||||
@sources[key].each do |source|
|
@sources[key].each do |source|
|
||||||
|
@logger.debug("Loading from: #{key}")
|
||||||
procs_for_source(source).each do |proc|
|
procs_for_source(source).each do |proc|
|
||||||
# TODO: Call the proc with a configuration object.
|
proc.call(top)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@logger.debug("Configuration loaded successfully")
|
||||||
|
|
||||||
|
top
|
||||||
end
|
end
|
||||||
|
|
||||||
protected
|
protected
|
||||||
|
@ -65,7 +74,7 @@ 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)
|
||||||
return source if source.is_a?(Proc)
|
return [source] if source.is_a?(Proc)
|
||||||
|
|
||||||
# Assume all string sources are actually pathnames
|
# Assume all string sources are actually pathnames
|
||||||
source = Pathname.new(source) if source.is_a?(String)
|
source = Pathname.new(source) if source.is_a?(String)
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
module Vagrant
|
module Vagrant
|
||||||
class Config
|
module Config
|
||||||
class NFSConfig < Base
|
class NFSConfig < Base
|
||||||
configures :nfs
|
configures :nfs
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
module Vagrant
|
module Vagrant
|
||||||
class Config
|
module Config
|
||||||
class PackageConfig < Base
|
class PackageConfig < Base
|
||||||
configures :package
|
configures :package
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
module Vagrant
|
module Vagrant
|
||||||
class Config
|
module Config
|
||||||
class SSHConfig < Base
|
class SSHConfig < Base
|
||||||
configures :ssh
|
configures :ssh
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
module Vagrant
|
module Vagrant
|
||||||
class Config
|
module Config
|
||||||
class VagrantConfig < Base
|
class VagrantConfig < Base
|
||||||
configures :vagrant
|
configures :vagrant
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@ require 'vagrant/config/vm/sub_vm'
|
||||||
require 'vagrant/config/vm/provisioner'
|
require 'vagrant/config/vm/provisioner'
|
||||||
|
|
||||||
module Vagrant
|
module Vagrant
|
||||||
class Config
|
module Config
|
||||||
class VMConfig < Base
|
class VMConfig < Base
|
||||||
configures :vm
|
configures :vm
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
module Vagrant
|
module Vagrant
|
||||||
class Config
|
module Config
|
||||||
class VMConfig < Base
|
class VMConfig < Base
|
||||||
# Represents a single configured provisioner for a VM.
|
# Represents a single configured provisioner for a VM.
|
||||||
class Provisioner
|
class Provisioner
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
module Vagrant
|
module Vagrant
|
||||||
class Config
|
module Config
|
||||||
class VMConfig < Base
|
class VMConfig < Base
|
||||||
# Represents a single sub-VM in a multi-VM environment.
|
# Represents a single sub-VM in a multi-VM environment.
|
||||||
class SubVM
|
class SubVM
|
||||||
|
|
|
@ -5,6 +5,18 @@ describe Vagrant::Config::Loader do
|
||||||
|
|
||||||
let(:instance) { described_class.new }
|
let(:instance) { described_class.new }
|
||||||
|
|
||||||
|
it "should load and return the configuration" do
|
||||||
|
proc = Proc.new do |config|
|
||||||
|
config.vagrant.dotfile_name = "foo"
|
||||||
|
end
|
||||||
|
|
||||||
|
instance.load_order = [:proc]
|
||||||
|
instance.set(:proc, proc)
|
||||||
|
config = instance.load
|
||||||
|
|
||||||
|
config.vagrant.dotfile_name.should == "foo"
|
||||||
|
end
|
||||||
|
|
||||||
it "should raise proper error if there is a syntax error in a Vagrantfile" do
|
it "should raise proper error if there is a syntax error in a Vagrantfile" do
|
||||||
instance.load_order = [:file]
|
instance.load_order = [:file]
|
||||||
instance.set(:file, temporary_file("Vagrant:^Config"))
|
instance.set(:file, temporary_file("Vagrant:^Config"))
|
||||||
|
|
|
@ -5,20 +5,6 @@ class ConfigTest < Test::Unit::TestCase
|
||||||
@klass = Vagrant::Config
|
@klass = Vagrant::Config
|
||||||
end
|
end
|
||||||
|
|
||||||
context "with the class" do
|
|
||||||
should "allow access to the last proc" do
|
|
||||||
foo = mock("object")
|
|
||||||
foo.expects(:call).once
|
|
||||||
|
|
||||||
@klass.run { |config| foo.call }
|
|
||||||
value = @klass.last_proc.first
|
|
||||||
assert value.is_a?(Proc)
|
|
||||||
value.call(nil)
|
|
||||||
|
|
||||||
assert @klass.last_proc.nil?
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
context "with an instance" do
|
context "with an instance" do
|
||||||
setup do
|
setup do
|
||||||
@instance = @klass.new
|
@instance = @klass.new
|
||||||
|
|
Loading…
Reference in New Issue