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



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

def initialize
  @hosts = []
  @exports = {}
  @imports = []
  @autoconfigure = UNSET_VALUE
  @add_localhost_hostnames = UNSET_VALUE
  @sync_hosts = UNSET_VALUE
end

Instance Attribute Details

#add_localhost_hostnamesTrueClass, FalseClass



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

def add_localhost_hostnames
  @add_localhost_hostnames
end

#autoconfigureTrueClass, FalseClass



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

def autoconfigure
  @autoconfigure
end

#exportsHash{String => Array<Array<String, Array<String>>>}

Returns A hash containing named lists of [address, [aliases]] tuples that are exported by this VM. These exports can be collected by other VMs using the #imports option.

Since:

  • 2.7.0



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

def exports
  @exports
end

#hostsObject

Returns the value of attribute hosts.



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

def hosts
  @hosts
end

#importsArray<String>

Returns A list of exports to collect from other VMs.

Since:

  • 2.7.0



42
43
44
# File 'lib/vagrant-hosts/config.rb', line 42

def imports
  @imports
end

#sync_hostsTrueClass, FalseClass



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

def sync_hosts
  @sync_hosts
end

Instance Method Details

#add_host(address, aliases) ⇒ Object

Register a host for entry



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

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

#add_ipv6_multicastObject

All IPv6 multicast addresses



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

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



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/vagrant-hosts/config.rb', line 70

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

  if @add_localhost_hostnames == UNSET_VALUE
    @add_localhost_hostnames = true
  end

  @sync_hosts = false if @sync_hosts == UNSET_VALUE
end

#merge(other) ⇒ VagrantHosts::Config



88
89
90
91
92
93
# File 'lib/vagrant-hosts/config.rb', line 88

def merge(other)
  result = super
  result.instance_variable_set(:@hosts, self.hosts.dup + other.hosts.dup)

  result
end

#validate(machine) ⇒ Object



95
96
97
98
99
100
101
102
103
104
# File 'lib/vagrant-hosts/config.rb', line 95

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