Sha256: 375363c5f2fb23b35949fbe97dfe30e585f03e04f44f8d5ff303007cea93157a

Contents?: true

Size: 698 Bytes

Versions: 4

Compression:

Stored size: 698 Bytes

Contents

# Provide a base class for syncing hosts entries on Windows systems.
class VagrantHosts::Cap::SyncHosts::Windows < VagrantHosts::Cap::SyncHosts::Base

  def update_hosts
    host_entries = []
    all_hosts(@config).each do |(address, aliases)|
      aliases.each do |name|
        host_entries << "#{address} #{name}"
      end
    end

    script = []
    script << '$HostsPath = "$env:windir\\System32\\drivers\\etc\\hosts"'
    script << '$Hosts = gc $HostsPath'

    host_defs = "'" + host_entries.join('\', \'') + "'"
    script << "@(#{host_defs}) | % { if (\$Hosts -notcontains \$_) { Add-Content -Path \$HostsPath -Value \$_ }}"

    @machine.communicate.sudo(script.join("; "))
  end

end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
vagrant-hosts-2.4.0 lib/vagrant-hosts/cap/sync_hosts/windows.rb
vagrant-hosts-2.3.0 lib/vagrant-hosts/cap/sync_hosts/windows.rb
vagrant-hosts-2.2.4 lib/vagrant-hosts/cap/sync_hosts/windows.rb
vagrant-hosts-2.2.3 lib/vagrant-hosts/cap/sync_hosts/windows.rb