Skip to content

Commit 8ec6108

Browse files
committed
Merge pull request #98 from pbitty/refactor_module
migrate HostsFile code into its own class
2 parents 7e2ac2a + 2e54e3f commit 8ec6108

File tree

7 files changed

+227
-220
lines changed

7 files changed

+227
-220
lines changed

lib/vagrant-hostmanager/action/update_all.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
require 'vagrant-hostmanager/hosts_file'
1+
require 'vagrant-hostmanager/hosts_file/updater'
22
require 'vagrant-hostmanager/util'
33

44
module VagrantPlugins
55
module HostManager
66
module Action
77
class UpdateAll
8-
include HostsFile
98

109
def initialize(app, env)
1110
@app = app
1211
@machine = env[:machine]
1312
@global_env = @machine.env
1413
@provider = @machine.provider_name
1514
@config = Util.get_config(@global_env)
15+
@updater = HostsFile::Updater.new(@global_env, @provider)
1616
@logger = Log4r::Logger.new('vagrant::hostmanager::update_all')
1717
end
1818

@@ -31,14 +31,14 @@ def call(env)
3131
@global_env.active_machines.each do |name, p|
3232
if p == @provider
3333
machine = @global_env.machine(name, p)
34-
update_guest(machine)
34+
@updater.update_guest(machine)
3535
end
3636
end
3737

3838
# update /etc/hosts files on host if enabled
3939
if @machine.config.hostmanager.manage_host?
4040
env[:ui].info I18n.t('vagrant_hostmanager.action.update_host')
41-
update_host
41+
@updater.update_host
4242
end
4343
end
4444
end

lib/vagrant-hostmanager/action/update_guest.rb

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,23 @@
1-
require 'vagrant-hostmanager/hosts_file'
1+
require 'vagrant-hostmanager/hosts_file/updater'
22
require 'vagrant-hostmanager/util'
33

44
module VagrantPlugins
55
module HostManager
66
module Action
77
class UpdateGuest
8-
include HostsFile
98

109
def initialize(app, env)
1110
@app = app
1211
@machine = env[:machine]
13-
@global_env = @machine.env
14-
@provider = env[:provider]
15-
@config = Util.get_config(@global_env)
12+
@updater = HostsFile::Updater.new(@machine.env, env[:provider])
1613
@logger = Log4r::Logger.new('vagrant::hostmanager::update_guest')
1714
end
1815

1916
def call(env)
2017
env[:ui].info I18n.t('vagrant_hostmanager.action.update_guest', {
2118
:name => @machine.name
2219
})
23-
update_guest(@machine)
20+
@updater.update_guest(@machine)
2421

2522
@app.call(env)
2623
end
Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,30 @@
1-
require 'vagrant-hostmanager/hosts_file'
1+
require 'vagrant-hostmanager/hosts_file/updater'
22
require 'vagrant-hostmanager/util'
33

44
module VagrantPlugins
55
module HostManager
66
module Action
77
class UpdateHost
8-
include HostsFile
98

109
def initialize(app, env)
1110
@app = app
12-
@global_env = env[:global_env]
13-
@provider = env[:provider]
14-
@config = Util.get_config(@global_env)
11+
12+
global_env = env[:global_env]
13+
@config = Util.get_config(global_env)
14+
@updater = HostsFile::Updater.new(global_env, env[:provider])
15+
1516
@logger = Log4r::Logger.new('vagrant::hostmanager::update_host')
1617
end
1718

1819
def call(env)
1920
if @config.hostmanager.manage_host?
2021
env[:ui].info I18n.t('vagrant_hostmanager.action.update_host')
21-
update_host
22+
@updater.update_host
2223
end
2324

2425
@app.call(env)
2526
end
2627
end
2728
end
2829
end
29-
end
30-
30+
end

lib/vagrant-hostmanager/command.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
module VagrantPlugins
22
module HostManager
33
class Command < Vagrant.plugin('2', :command)
4-
include HostsFile
54

65
# Show description when `vagrant list-commands` is triggered
76
def self.synopsis

lib/vagrant-hostmanager/hosts_file.rb

Lines changed: 0 additions & 195 deletions
This file was deleted.

0 commit comments

Comments
 (0)