Sha256: bb0146a5d549341351f4f70f139f149499cd6ef515fe01fe735c0e133bdd31d6

Contents?: true

Size: 706 Bytes

Versions: 8

Compression:

Stored size: 706 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 << '$HostsLocation = "$env:windir\\System32\\drivers\\etc\\hosts";'

    host_entries.each do |entry|
      script << "\$HostEntry = \"#{entry}\""
      script << "if (!((gc \$HostsLocation) -contains $HostEntry)) { Add-Content -Path $HostsLocation -Value $HostEntry; }"
    end

    @machine.communicate.sudo(script.join("\r\n"))
  end

end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
vagrant-hosts-2.2.1 lib/vagrant-hosts/cap/sync_hosts/windows.rb
vagrant-hosts-2.2.0 lib/vagrant-hosts/cap/sync_hosts/windows.rb
vagrant-hosts-2.1.5 lib/vagrant-hosts/cap/sync_hosts/windows.rb
vagrant-hosts-2.1.4 lib/vagrant-hosts/cap/sync_hosts/windows.rb
vagrant-hosts-2.1.3 lib/vagrant-hosts/cap/sync_hosts/windows.rb
vagrant-hosts-2.1.2 lib/vagrant-hosts/cap/sync_hosts/windows.rb
vagrant-hosts-2.1.1 lib/vagrant-hosts/cap/sync_hosts/windows.rb
vagrant-hosts-2.1.0 lib/vagrant-hosts/cap/sync_hosts/windows.rb