core: Silence ruby warnings when loading external machines

This commit is contained in:
Mitchell Hashimoto 2014-03-14 17:41:01 -07:00
parent a0e9f46251
commit 4349800374
2 changed files with 27 additions and 6 deletions

View File

@ -1,6 +1,7 @@
require 'log4r' require 'log4r'
require "vagrant/util/safe_puts" require "vagrant/util/safe_puts"
require "vagrant/util/silence_warnings"
module Vagrant module Vagrant
module Plugin module Plugin
@ -130,12 +131,18 @@ module Vagrant
@env.machine_index.release(entry) @env.machine_index.release(entry)
# Create an environment for this location and yield the # Create an environment for this location and yield the
# machine in that environment. # 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( env = Vagrant::Environment.new(
cwd: entry.vagrantfile_path, cwd: entry.vagrantfile_path,
home_path: @env.home_path, home_path: @env.home_path,
) )
next env.machine(entry.name.to_sym, entry.provider.to_sym) env.machine(entry.name.to_sym, entry.provider.to_sym)
end
next machine
end end
active_machines.each do |active_name, active_provider| active_machines.each do |active_name, active_provider|

View File

@ -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