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.



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

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.



15
16
17
# File 'lib/vagrant-hosts/config.rb', line 15

def add_localhost_hostnames
  @add_localhost_hostnames
end

#autoconfigureTrueClass, FalseClass

Returns If hosts should be generated from the other vagrant machines.

Returns:

  • (TrueClass, FalseClass)

    If hosts should be generated from the other vagrant machines



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



27
28
29
# File 'lib/vagrant-hosts/config.rb', line 27

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

#add_ipv6_multicastObject

All IPv6 multicast addresses



32
33
34
35
36
37
38
# File 'lib/vagrant-hosts/config.rb', line 32

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



40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/vagrant-hosts/config.rb', line 40

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:



56
57
58
59
60
# File 'lib/vagrant-hosts/config.rb', line 56

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

#validate(machine) ⇒ Object



62
63
64
65
66
67
68
69
70
71
# File 'lib/vagrant-hosts/config.rb', line 62

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