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/loader'
|
||||
# require 'vagrant/config/error_recorder'
|
||||
require 'vagrant/config/error_recorder'
|
||||
require 'vagrant/config/top'
|
||||
|
||||
# # The built-in configuration classes
|
||||
# require 'vagrant/config/vagrant'
|
||||
# require 'vagrant/config/ssh'
|
||||
# require 'vagrant/config/nfs'
|
||||
# require 'vagrant/config/vm'
|
||||
# require 'vagrant/config/package'
|
||||
require 'vagrant/config/vagrant'
|
||||
require 'vagrant/config/ssh'
|
||||
require 'vagrant/config/nfs'
|
||||
require 'vagrant/config/vm'
|
||||
require 'vagrant/config/package'
|
||||
|
||||
module Vagrant
|
||||
module Config
|
||||
autoload :Container, 'vagrant/config/container'
|
||||
|
||||
CONFIGURE_MUTEX = Mutex.new
|
||||
|
||||
# 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
|
||||
class Config
|
||||
module Config
|
||||
# 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
|
||||
# class.
|
||||
|
|
|
@ -43,19 +43,28 @@ module Vagrant
|
|||
# This loads the configured sources in the configured order and returns
|
||||
# an actual configuration object that is ready to be used.
|
||||
def load
|
||||
@logger.debug("Loading configuration in order: #{@load_order.inspect}")
|
||||
|
||||
unknown_sources = @sources.keys - @load_order
|
||||
if !unknown_sources.empty?
|
||||
# TODO: Raise exception here perhaps.
|
||||
@logger.error("Unknown config sources: #{unknown_sources.inspect}")
|
||||
end
|
||||
|
||||
top = Top.new
|
||||
|
||||
@load_order.each do |key|
|
||||
@sources[key].each do |source|
|
||||
@logger.debug("Loading from: #{key}")
|
||||
procs_for_source(source).each do |proc|
|
||||
# TODO: Call the proc with a configuration object.
|
||||
proc.call(top)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@logger.debug("Configuration loaded successfully")
|
||||
|
||||
top
|
||||
end
|
||||
|
||||
protected
|
||||
|
@ -65,7 +74,7 @@ module Vagrant
|
|||
# the configuration object and are expected to mutate this
|
||||
# configuration object.
|
||||
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
|
||||
source = Pathname.new(source) if source.is_a?(String)
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
module Vagrant
|
||||
class Config
|
||||
module Config
|
||||
class NFSConfig < Base
|
||||
configures :nfs
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
module Vagrant
|
||||
class Config
|
||||
module Config
|
||||
class PackageConfig < Base
|
||||
configures :package
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
module Vagrant
|
||||
class Config
|
||||
module Config
|
||||
class SSHConfig < Base
|
||||
configures :ssh
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
module Vagrant
|
||||
class Config
|
||||
module Config
|
||||
class VagrantConfig < Base
|
||||
configures :vagrant
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@ require 'vagrant/config/vm/sub_vm'
|
|||
require 'vagrant/config/vm/provisioner'
|
||||
|
||||
module Vagrant
|
||||
class Config
|
||||
module Config
|
||||
class VMConfig < Base
|
||||
configures :vm
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
module Vagrant
|
||||
class Config
|
||||
module Config
|
||||
class VMConfig < Base
|
||||
# Represents a single configured provisioner for a VM.
|
||||
class Provisioner
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
module Vagrant
|
||||
class Config
|
||||
module Config
|
||||
class VMConfig < Base
|
||||
# Represents a single sub-VM in a multi-VM environment.
|
||||
class SubVM
|
||||
|
|
|
@ -5,6 +5,18 @@ describe Vagrant::Config::Loader do
|
|||
|
||||
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
|
||||
instance.load_order = [:file]
|
||||
instance.set(:file, temporary_file("Vagrant:^Config"))
|
||||
|
|
|
@ -5,20 +5,6 @@ class ConfigTest < Test::Unit::TestCase
|
|||
@klass = Vagrant::Config
|
||||
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
|
||||
setup do
|
||||
@instance = @klass.new
|
||||
|
|
Loading…
Reference in New Issue