Skip to content

Commit 936e7e4

Browse files
committed
Merge pull request #97 from pbitty/config_compat
extract old vagrant version compatibility code into util method
2 parents f92153e + 0bc2f30 commit 936e7e4

File tree

5 files changed

+21
-32
lines changed

5 files changed

+21
-32
lines changed

lib/vagrant-hostmanager/action/update_all.rb

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
require 'vagrant-hostmanager/hosts_file'
2+
require 'vagrant-hostmanager/util'
23

34
module VagrantPlugins
45
module HostManager
@@ -11,14 +12,7 @@ def initialize(app, env)
1112
@machine = env[:machine]
1213
@global_env = @machine.env
1314
@provider = @machine.provider_name
14-
15-
# config_global is deprecated from v1.5
16-
if Gem::Version.new(::Vagrant::VERSION) >= Gem::Version.new('1.5')
17-
@config = @global_env.vagrantfile.config
18-
else
19-
@config = @global_env.config_global
20-
end
21-
15+
@config = Util.get_config(@global_env)
2216
@logger = Log4r::Logger.new('vagrant::hostmanager::update_all')
2317
end
2418

lib/vagrant-hostmanager/action/update_guest.rb

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
require 'vagrant-hostmanager/hosts_file'
2+
require 'vagrant-hostmanager/util'
23

34
module VagrantPlugins
45
module HostManager
@@ -11,14 +12,7 @@ def initialize(app, env)
1112
@machine = env[:machine]
1213
@global_env = @machine.env
1314
@provider = env[:provider]
14-
15-
# config_global is deprecated from v1.5
16-
if Gem::Version.new(::Vagrant::VERSION) >= Gem::Version.new('1.5')
17-
@config = @global_env.vagrantfile.config
18-
else
19-
@config = @global_env.config_global
20-
end
21-
15+
@config = Util.get_config(@global_env)
2216
@logger = Log4r::Logger.new('vagrant::hostmanager::update_guest')
2317
end
2418

lib/vagrant-hostmanager/action/update_host.rb

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
require 'vagrant-hostmanager/hosts_file'
2+
require 'vagrant-hostmanager/util'
23

34
module VagrantPlugins
45
module HostManager
@@ -10,14 +11,7 @@ def initialize(app, env)
1011
@app = app
1112
@global_env = env[:global_env]
1213
@provider = env[:provider]
13-
14-
# config_global is deprecated from v1.5
15-
if Gem::Version.new(::Vagrant::VERSION) >= Gem::Version.new('1.5')
16-
@config = @global_env.vagrantfile.config
17-
else
18-
@config = @global_env.config_global
19-
end
20-
14+
@config = Util.get_config(@global_env)
2115
@logger = Log4r::Logger.new('vagrant::hostmanager::update_host')
2216
end
2317

lib/vagrant-hostmanager/provisioner.rb

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,7 @@ def initialize(machine, config)
77
super(machine, config)
88
@global_env = machine.env
99
@provider = machine.provider_name
10-
11-
# config_global is deprecated from v1.5
12-
if Gem::Version.new(::Vagrant::VERSION) >= Gem::Version.new('1.5')
13-
@config = @global_env.vagrantfile.config
14-
else
15-
@config = @global_env.config_global
16-
end
17-
10+
@config = Util.get_config(@global_env)
1811
end
1912

2013
def provision

lib/vagrant-hostmanager/util.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
module VagrantPlugins
2+
module HostManager
3+
module Util
4+
def self.get_config(env)
5+
# config_global has been removed from v1.5
6+
if Gem::Version.new(::Vagrant::VERSION) >= Gem::Version.new('1.5')
7+
env.vagrantfile.config
8+
else
9+
env.config_global
10+
end
11+
end
12+
end
13+
end
14+
end

0 commit comments

Comments
 (0)