From 434980037480b3d1d9de0213e6d68416c27b1c07 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Fri, 14 Mar 2014 17:41:01 -0700 Subject: [PATCH] core: Silence ruby warnings when loading external machines --- lib/vagrant/plugin/v2/command.rb | 19 +++++++++++++------ lib/vagrant/util/silence_warnings.rb | 14 ++++++++++++++ 2 files changed, 27 insertions(+), 6 deletions(-) create mode 100644 lib/vagrant/util/silence_warnings.rb diff --git a/lib/vagrant/plugin/v2/command.rb b/lib/vagrant/plugin/v2/command.rb index 3356d0320..52dd63733 100644 --- a/lib/vagrant/plugin/v2/command.rb +++ b/lib/vagrant/plugin/v2/command.rb @@ -1,6 +1,7 @@ require 'log4r' require "vagrant/util/safe_puts" +require "vagrant/util/silence_warnings" module Vagrant module Plugin @@ -130,12 +131,18 @@ module Vagrant @env.machine_index.release(entry) # Create an environment for this location and yield the - # machine in that environment. - env = Vagrant::Environment.new( - cwd: entry.vagrantfile_path, - home_path: @env.home_path, - ) - next env.machine(entry.name.to_sym, entry.provider.to_sym) + # machine in that environment. We silence warnings here because + # Vagrantfiles often have constants, so people would otherwise + # constantly (heh) get "already initialized constant" warnings. + machine = Vagrant::Util::SilenceWarnings.silence! do + env = Vagrant::Environment.new( + cwd: entry.vagrantfile_path, + home_path: @env.home_path, + ) + env.machine(entry.name.to_sym, entry.provider.to_sym) + end + + next machine end active_machines.each do |active_name, active_provider| diff --git a/lib/vagrant/util/silence_warnings.rb b/lib/vagrant/util/silence_warnings.rb new file mode 100644 index 000000000..c5b251df8 --- /dev/null +++ b/lib/vagrant/util/silence_warnings.rb @@ -0,0 +1,14 @@ +module Vagrant + module Util + module SilenceWarnings + # This silences any Ruby warnings. + def self.silence! + original = $VERBOSE + $VERBOSE = nil + return yield + ensure + $VERBOSE = original + end + end + end +end