Class: VagrantVmHosts::Action

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant-vmhosts/action.rb

Instance Method Summary collapse

Constructor Details

#initialize(app, env) ⇒ Action

Returns a new instance of Action.



3
4
5
# File 'lib/vagrant-vmhosts/action.rb', line 3

def initialize(app, env)
  @app = app
end

Instance Method Details

#call(env) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/vagrant-vmhosts/action.rb', line 7

def call(env)
  @app.call(env)

  hosts = env[:vm].config.vmhosts.list

  if !hosts.empty?
    env[:ui].info I18n.t("vagrant.plugins.vmhosts.adding")
    hosts.each do |host|
      if !env[:vm].channel.test("grep '^#{host['ip']}[[:space:]]' /etc/hosts")
        env[:vm].channel.sudo("printf '%s\t%s %s\n' '#{host['ip']}' '#{host['canonical']}' '#{host['aliases'].join(' ')}' >> /etc/hosts")
      end
    end
  end
end