Sha256: b351ec5e790bcddbe854af9a0f073027693df25626aab72aad166e0ea0790e51

Contents?: true

Size: 823 Bytes

Versions: 7

Compression:

Stored size: 823 Bytes

Contents

# Provide an abstract base class for syncing hosts entries
class VagrantHosts::Cap::SyncHosts::Base

  require 'vagrant-hosts/addresses'
  include VagrantHosts::Addresses

  def self.sync_hosts(machine, config)
    new(machine, config).sync!
  end

  def initialize(machine, config)
    @machine, @config = machine, config
    @env = @machine.env
  end

  def sync!
    hostname = @machine.config.vm.hostname || @machine.name.to_s
    change_host_name(hostname)

    # call to method not implemented by abstract base class
    update_hosts
  end

  private

  # @param name [String] The new hostname to apply on the guest
  def change_host_name(name)
    case Vagrant::VERSION
    when /^1\.1/
      @machine.guest.change_host_name(name)
    else
      @machine.guest.capability(:change_host_name, name)
    end
  end

end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
vagrant-hosts-2.7.1 lib/vagrant-hosts/cap/sync_hosts/base.rb
vagrant-hosts-2.6.2 lib/vagrant-hosts/cap/sync_hosts/base.rb
vagrant-hosts-2.6.1 lib/vagrant-hosts/cap/sync_hosts/base.rb
vagrant-hosts-2.6.0 lib/vagrant-hosts/cap/sync_hosts/base.rb
vagrant-hosts-2.5.0 lib/vagrant-hosts/cap/sync_hosts/base.rb
vagrant-hosts-2.4.0 lib/vagrant-hosts/cap/sync_hosts/base.rb
vagrant-hosts-2.3.0 lib/vagrant-hosts/cap/sync_hosts/base.rb