Move config loader order out from an ivar into a param for the #load
method
This commit is contained in:
parent
1559f7b7a7
commit
0180ed849d
|
@ -12,10 +12,6 @@ module Vagrant
|
|||
# set later always overrides those set earlier; this is how
|
||||
# configuration "scoping" is implemented.
|
||||
class Loader
|
||||
# This is an array of symbols specifying the order in which
|
||||
# configuration is loaded. For examples, see the class documentation.
|
||||
attr_accessor :load_order
|
||||
|
||||
# Initializes a configuration loader.
|
||||
#
|
||||
# @param [Registry] versions A registry of the available versions and
|
||||
|
@ -69,12 +65,16 @@ module Vagrant
|
|||
@sources[name] = procs
|
||||
end
|
||||
|
||||
# This loads the configured sources in the configured order and returns
|
||||
# This loads the configuration sources in the given order and returns
|
||||
# an actual configuration object that is ready to be used.
|
||||
def load
|
||||
@logger.debug("Loading configuration in order: #{@load_order.inspect}")
|
||||
#
|
||||
# @param [Array<Symbol>] order The order of configuration to load.
|
||||
# @return [Object] The configuration object. This is different for
|
||||
# each configuration version.
|
||||
def load(order)
|
||||
@logger.debug("Loading configuration in order: #{order.inspect}")
|
||||
|
||||
unknown_sources = @sources.keys - @load_order
|
||||
unknown_sources = @sources.keys - order
|
||||
if !unknown_sources.empty?
|
||||
# TODO: Raise exception here perhaps.
|
||||
@logger.error("Unknown config sources: #{unknown_sources.inspect}")
|
||||
|
@ -87,7 +87,7 @@ module Vagrant
|
|||
# This will hold our result
|
||||
result = current_config_klass.init
|
||||
|
||||
@load_order.each do |key|
|
||||
order.each do |key|
|
||||
next if !@sources.has_key?(key)
|
||||
|
||||
@sources[key].each do |version, proc|
|
||||
|
@ -182,7 +182,7 @@ module Vagrant
|
|||
# Report syntax errors in a nice way.
|
||||
raise Errors::VagrantfileSyntaxError, :file => e.message
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -40,8 +40,7 @@ describe Vagrant::Config::Loader do
|
|||
|
||||
describe "basic loading" do
|
||||
it "should ignore non-existent load order keys" do
|
||||
instance.load_order = [:foo]
|
||||
instance.load
|
||||
instance.load([:foo])
|
||||
end
|
||||
|
||||
it "should load and return the configuration" do
|
||||
|
@ -49,9 +48,8 @@ describe Vagrant::Config::Loader do
|
|||
config[:foo] = "yep"
|
||||
end
|
||||
|
||||
instance.load_order = [:proc]
|
||||
instance.set(:proc, [[current_version, proc]])
|
||||
config = instance.load
|
||||
config = instance.load([:proc])
|
||||
|
||||
config[:foo].should == "yep"
|
||||
end
|
||||
|
@ -71,9 +69,8 @@ describe Vagrant::Config::Loader do
|
|||
end
|
||||
|
||||
# Run the actual configuration and assert that we get the proper result
|
||||
instance.load_order = [:proc]
|
||||
instance.set(:proc, [[current_version, proc]])
|
||||
config = instance.load
|
||||
config = instance.load([:proc])
|
||||
config[:foo].should == "yep"
|
||||
config[:finalized].should == true
|
||||
end
|
||||
|
@ -95,9 +92,8 @@ describe Vagrant::Config::Loader do
|
|||
|
||||
# Load a version 1 proc, and verify it is upgraded to version 2
|
||||
proc = lambda { |config| config[:foo] = "yep" }
|
||||
instance.load_order = [:proc]
|
||||
instance.set(:proc, [["1", proc]])
|
||||
config = instance.load
|
||||
config = instance.load([:proc])
|
||||
config[:foo].should == "yep"
|
||||
config[:v2].should == true
|
||||
end
|
||||
|
@ -111,11 +107,10 @@ describe Vagrant::Config::Loader do
|
|||
count += 1
|
||||
end
|
||||
|
||||
instance.load_order = [:proc]
|
||||
instance.set(:proc, [[current_version, proc]])
|
||||
|
||||
5.times do
|
||||
result = instance.load
|
||||
result = instance.load([:proc])
|
||||
|
||||
# Verify the config result
|
||||
result[:foo].should == "yep"
|
||||
|
@ -131,9 +126,8 @@ describe Vagrant::Config::Loader do
|
|||
# We test both setting a file multiple times as well as multiple
|
||||
# loads, since both should not cache the data.
|
||||
file = temporary_file("$_config_data += 1")
|
||||
instance.load_order = [:file]
|
||||
5.times { instance.set(:file, file) }
|
||||
5.times { instance.load }
|
||||
5.times { instance.load([:file]) }
|
||||
|
||||
$_config_data.should == 1
|
||||
end
|
||||
|
@ -143,18 +137,16 @@ describe Vagrant::Config::Loader do
|
|||
|
||||
file = temporary_file("$_config_data += 1")
|
||||
|
||||
instance.load_order = [:proc]
|
||||
instance.set(:proc, file)
|
||||
5.times { instance.load }
|
||||
5.times { instance.load([:proc]) }
|
||||
|
||||
instance.set(:proc, file)
|
||||
5.times { instance.load }
|
||||
5.times { instance.load([:proc]) }
|
||||
|
||||
$_config_data.should == 1
|
||||
end
|
||||
|
||||
it "should raise proper error if there is a syntax error in a Vagrantfile" do
|
||||
instance.load_order = [:file]
|
||||
expect { instance.set(:file, temporary_file("Vagrant:^Config")) }.
|
||||
to raise_exception(Vagrant::Errors::VagrantfileSyntaxError)
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue