Sha256: 1d0143cdfb8d70417a6455d00c32d6dac8935b1fd3fa782547ae676fbd8a2f81

Contents?: true

Size: 748 Bytes

Versions: 12

Compression:

Stored size: 748 Bytes

Contents

# Provide a base class for syncing hosts entries on POSIX systems.

require 'tempfile'

class VagrantHosts::Cap::SyncHosts::POSIX < VagrantHosts::Cap::SyncHosts::Base

  private

  def upload_tmphosts
    cache = Tempfile.new('tmp-hosts')
    cache.write(format_hosts)
    cache.flush
    @machine.communicate.upload(cache.path, '/tmp/hosts')
  end

  def update_hosts
    upload_tmphosts
    @machine.communicate.sudo('install -m 644 /tmp/hosts /etc/hosts')
  end

  # Generates content appropriate for a linux hosts file
  #
  # @return [String] All hosts in the config joined into hosts records
  def format_hosts
    all_hosts(@config).inject('') do |str, (address, aliases)|
      str << "#{address} #{aliases.join(' ')}\n"
    end
  end

end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
vagrant-hosts-2.3.0 lib/vagrant-hosts/cap/sync_hosts/posix.rb
vagrant-hosts-2.2.4 lib/vagrant-hosts/cap/sync_hosts/posix.rb
vagrant-hosts-2.2.3 lib/vagrant-hosts/cap/sync_hosts/posix.rb
vagrant-hosts-2.2.2 lib/vagrant-hosts/cap/sync_hosts/posix.rb
vagrant-hosts-2.2.1 lib/vagrant-hosts/cap/sync_hosts/posix.rb
vagrant-hosts-2.2.0 lib/vagrant-hosts/cap/sync_hosts/posix.rb
vagrant-hosts-2.1.5 lib/vagrant-hosts/cap/sync_hosts/posix.rb
vagrant-hosts-2.1.4 lib/vagrant-hosts/cap/sync_hosts/posix.rb
vagrant-hosts-2.1.3 lib/vagrant-hosts/cap/sync_hosts/posix.rb
vagrant-hosts-2.1.2 lib/vagrant-hosts/cap/sync_hosts/posix.rb
vagrant-hosts-2.1.1 lib/vagrant-hosts/cap/sync_hosts/posix.rb
vagrant-hosts-2.1.0 lib/vagrant-hosts/cap/sync_hosts/posix.rb