Class: VagrantHosts::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant-hosts/config.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfig

Returns a new instance of Config.



21
22
23
24
25
# File 'lib/vagrant-hosts/config.rb', line 21

def initialize
  @hosts = []
  @autoconfigure = UNSET_VALUE
  @add_localhost_hostnames = UNSET_VALUE
end

Instance Attribute Details

#add_localhost_hostnamesObject

Returns the value of attribute add_localhost_hostnames.



19
20
21
# File 'lib/vagrant-hosts/config.rb', line 19

def add_localhost_hostnames
  @add_localhost_hostnames
end

#autoconfigureTrueClass, FalseClass

Returns A boolean indicating whether a ‘127.0.1.1` entry should be added mapping to the FQDN of the VM. Default: `true`.

Returns:

  • (TrueClass, FalseClass)

    A boolean indicating whether a ‘127.0.1.1` entry should be added mapping to the FQDN of the VM. Default: `true`.



13
14
15
# File 'lib/vagrant-hosts/config.rb', line 13

def autoconfigure
  @autoconfigure
end

#hostsObject

Returns the value of attribute hosts.



8
9
10
# File 'lib/vagrant-hosts/config.rb', line 8

def hosts
  @hosts
end

Instance Method Details

#add_host(address, aliases) ⇒ Object

Register a host for entry

Parameters:

  • address (String)

    The IP address for aliases

  • aliases (Array)

    An array of hostnames to assign to the IP address



31
32
33
# File 'lib/vagrant-hosts/config.rb', line 31

def add_host(address, aliases)
  @hosts << [address, aliases]
end

#add_ipv6_multicastObject

All IPv6 multicast addresses



36
37
38
39
40
41
42
# File 'lib/vagrant-hosts/config.rb', line 36

def add_ipv6_multicast
  add_host '::1',     ['ip6-localhost', 'ip6-loopback']
  add_host 'fe00::0', ['ip6-localnet']
  add_host 'ff00::0', ['ip6-mcastprefix']
  add_host 'ff02::1', ['ip6-allnodes']
  add_host 'ff02::2', ['ip6-allrouters']
end

#finalize!Object



44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/vagrant-hosts/config.rb', line 44

def finalize!
  if @autoconfigure == UNSET_VALUE
   if  @hosts.empty?
      @autoconfigure = true
    else
      @autoconfigure = false
    end
  end

  if @add_localhost_hostnames == UNSET_VALUE
    @add_localhost_hostnames = true
  end
end

#merge(other) ⇒ VagrantHosts::Config

Returns The merged results.

Parameters:

Returns:



60
61
62
63
64
# File 'lib/vagrant-hosts/config.rb', line 60

def merge(other)
  super.tap do |result|
    result.hosts += other.hosts
  end
end

#validate(machine) ⇒ Object



66
67
68
69
70
71
72
73
74
75
# File 'lib/vagrant-hosts/config.rb', line 66

def validate(machine)
  errors = []
  @hosts.each do |(address, aliases)|
    unless aliases.is_a? Array
      errors << "#{address} should have an array of aliases, got #{aliases.inspect}:#{aliases.class}"
    end
  end

  {"Vagrant Hosts" => errors}
end