extract old vagrant version compatibility code into util method

This commit is contained in:
Paulo Bittencourt 2014-06-01 15:29:29 -04:00
parent f92153ed94
commit 0bc2f30b7b
5 changed files with 21 additions and 32 deletions

View File

@ -1,4 +1,5 @@
require 'vagrant-hostmanager/hosts_file' require 'vagrant-hostmanager/hosts_file'
require 'vagrant-hostmanager/util'
module VagrantPlugins module VagrantPlugins
module HostManager module HostManager
@ -11,14 +12,7 @@ module VagrantPlugins
@machine = env[:machine] @machine = env[:machine]
@global_env = @machine.env @global_env = @machine.env
@provider = @machine.provider_name @provider = @machine.provider_name
@config = Util.get_config(@global_env)
# config_global is deprecated from v1.5
if Gem::Version.new(::Vagrant::VERSION) >= Gem::Version.new('1.5')
@config = @global_env.vagrantfile.config
else
@config = @global_env.config_global
end
@logger = Log4r::Logger.new('vagrant::hostmanager::update_all') @logger = Log4r::Logger.new('vagrant::hostmanager::update_all')
end end

View File

@ -1,4 +1,5 @@
require 'vagrant-hostmanager/hosts_file' require 'vagrant-hostmanager/hosts_file'
require 'vagrant-hostmanager/util'
module VagrantPlugins module VagrantPlugins
module HostManager module HostManager
@ -11,14 +12,7 @@ module VagrantPlugins
@machine = env[:machine] @machine = env[:machine]
@global_env = @machine.env @global_env = @machine.env
@provider = env[:provider] @provider = env[:provider]
@config = Util.get_config(@global_env)
# config_global is deprecated from v1.5
if Gem::Version.new(::Vagrant::VERSION) >= Gem::Version.new('1.5')
@config = @global_env.vagrantfile.config
else
@config = @global_env.config_global
end
@logger = Log4r::Logger.new('vagrant::hostmanager::update_guest') @logger = Log4r::Logger.new('vagrant::hostmanager::update_guest')
end end

View File

@ -1,4 +1,5 @@
require 'vagrant-hostmanager/hosts_file' require 'vagrant-hostmanager/hosts_file'
require 'vagrant-hostmanager/util'
module VagrantPlugins module VagrantPlugins
module HostManager module HostManager
@ -10,14 +11,7 @@ module VagrantPlugins
@app = app @app = app
@global_env = env[:global_env] @global_env = env[:global_env]
@provider = env[:provider] @provider = env[:provider]
@config = Util.get_config(@global_env)
# config_global is deprecated from v1.5
if Gem::Version.new(::Vagrant::VERSION) >= Gem::Version.new('1.5')
@config = @global_env.vagrantfile.config
else
@config = @global_env.config_global
end
@logger = Log4r::Logger.new('vagrant::hostmanager::update_host') @logger = Log4r::Logger.new('vagrant::hostmanager::update_host')
end end

View File

@ -7,14 +7,7 @@ module VagrantPlugins
super(machine, config) super(machine, config)
@global_env = machine.env @global_env = machine.env
@provider = machine.provider_name @provider = machine.provider_name
@config = Util.get_config(@global_env)
# config_global is deprecated from v1.5
if Gem::Version.new(::Vagrant::VERSION) >= Gem::Version.new('1.5')
@config = @global_env.vagrantfile.config
else
@config = @global_env.config_global
end
end end
def provision def provision

View File

@ -0,0 +1,14 @@
module VagrantPlugins
module HostManager
module Util
def self.get_config(env)
# config_global has been removed from v1.5
if Gem::Version.new(::Vagrant::VERSION) >= Gem::Version.new('1.5')
env.vagrantfile.config
else
env.config_global
end
end
end
end
end