From 7549704c5b7d0a76db7df3224a3c659bc0f91745 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Wed, 5 Feb 2014 19:24:47 -0800 Subject: [PATCH] core: Environment#config_global is gone! --- lib/vagrant/action/general/package.rb | 3 +- lib/vagrant/environment.rb | 41 +++++++++------------------ lib/vagrant/vagrantfile.rb | 4 +++ test/unit/vagrant/vagrantfile_test.rb | 18 ++++++++++++ 4 files changed, 37 insertions(+), 29 deletions(-) diff --git a/lib/vagrant/action/general/package.rb b/lib/vagrant/action/general/package.rb index 996368d3a..f112e9ede 100644 --- a/lib/vagrant/action/general/package.rb +++ b/lib/vagrant/action/general/package.rb @@ -23,7 +23,8 @@ module Vagrant @app = app env["package.files"] ||= {} - env["package.output"] ||= env[:global_config].package.name + env["package.output"] ||= env[:machine].package.name + env["package.output"] ||= "package.box" end def call(env) diff --git a/lib/vagrant/environment.rb b/lib/vagrant/environment.rb index 72d218898..07a144445 100644 --- a/lib/vagrant/environment.rb +++ b/lib/vagrant/environment.rb @@ -236,39 +236,25 @@ module Vagrant @_boxes ||= BoxCollection.new(boxes_path, temp_dir_root: tmp_path) end - # This is the global config, comprised of loading configuration from - # the default, home, and root Vagrantfiles. This configuration is only - # really useful for reading the list of virtual machines, since each - # individual VM can override _most_ settings. + # Returns the {Config::Loader} that can be used to load Vagrantflies + # given the settings of this environment. # - # This is lazy-loaded upon first use. - # - # @return [Object] - def config_global - return @config_global if @config_global - - @logger.info("Initializing config...") + # @return [Config::Loader] + def config_loader + return @config_loader if @config_loader home_vagrantfile = nil root_vagrantfile = nil home_vagrantfile = find_vagrantfile(home_path) if home_path - root_vagrantfile = find_vagrantfile(root_path, @vagrantfile_name) if root_path + if root_path + root_vagrantfile = find_vagrantfile(root_path, @vagrantfile_name) + end - # Create the configuration loader and set the sources that are global. - # We use this to load the configuration, and the list of machines we are - # managing. Then, the actual individual configuration is loaded for - # each {#machine} call. - @config_loader = Config::Loader.new(Config::VERSIONS, Config::VERSIONS_ORDER) + @config_loader = Config::Loader.new( + Config::VERSIONS, Config::VERSIONS_ORDER) @config_loader.set(:home, home_vagrantfile) if home_vagrantfile @config_loader.set(:root, root_vagrantfile) if root_vagrantfile - - # Make the initial call to get the "global" config. This is mostly - # only useful to get the list of machines that we are managing. - # Because of this, we ignore any warnings or errors. - @config_global, _ = @config_loader.load([:home, :root]) - - # Return the config - @config_global + @config_loader end # This defines a hook point where plugin action hooks that are registered @@ -379,7 +365,7 @@ module Vagrant end def vagrantfile - @vagrantfile ||= Vagrantfile.new(@config_loader, [:home, :root]) + @vagrantfile ||= Vagrantfile.new(config_loader, [:home, :root]) end # Unload the environment, running completion hooks. The environment @@ -413,7 +399,7 @@ module Vagrant # that shouldn't be valid anymore, but we respect it here by assuming # its old behavior. No need to deprecate this because I thin it is # fairly harmless. - host_klass = config_global.vagrant.host + host_klass = vagrantfile.config.vagrant.host host_klass = nil if host_klass == :detect begin @@ -447,7 +433,6 @@ module Vagrant { :action_runner => action_runner, :box_collection => boxes, - :global_config => config_global, :hook => method(:hook), :host => host, :gems_path => gems_path, diff --git a/lib/vagrant/vagrantfile.rb b/lib/vagrant/vagrantfile.rb index afaf33da6..f6a660efc 100644 --- a/lib/vagrant/vagrantfile.rb +++ b/lib/vagrant/vagrantfile.rb @@ -9,6 +9,10 @@ module Vagrant # loading the configuration of a specific machine/provider combo, # etc. class Vagrantfile + # This is the configuration loaded as-is given the loader and + # keys to #initialize. + attr_reader :config + # Initializes by loading a Vagrantfile. # # @param [Config::Loader] loader Configuration loader that should diff --git a/test/unit/vagrant/vagrantfile_test.rb b/test/unit/vagrant/vagrantfile_test.rb index 5531605d5..623b2c208 100644 --- a/test/unit/vagrant/vagrantfile_test.rb +++ b/test/unit/vagrant/vagrantfile_test.rb @@ -13,6 +13,24 @@ describe Vagrant::Vagrantfile do subject { described_class.new(loader, keys) } + describe "#config" do + before do + keys << :test + end + + def configure(&block) + loader.set(:test, [["2", block]]) + end + + it "exposes the global configuration" do + configure do |config| + config.vm.box = "what" + end + + expect(subject.config.vm.box).to eq("what") + end + end + describe "#machine_config" do let(:iso_env) { isolated_environment } let(:boxes) { Vagrant::BoxCollection.new(iso_env.boxes_dir) }