Class: VagrantHosts::Config
- Inherits:
-
Object
- Object
- VagrantHosts::Config
- Defined in:
- lib/vagrant-hosts/config.rb
Instance Attribute Summary collapse
-
#add_localhost_hostnames ⇒ TrueClass, FalseClass
A boolean indicating whether a
127.0.1.1entry should be added mapping to the FQDN of the VM. -
#autoconfigure ⇒ TrueClass, FalseClass
If hosts should be generated from the other vagrant machines.
-
#exports ⇒ Hash{String => Array<Array<String, Array<String>>>}
A hash containing named lists of
[address, [aliases]]tuples that are exported by this VM. -
#hosts ⇒ Object
Returns the value of attribute hosts.
-
#imports ⇒ Array<String>
A list of exports to collect from other VMs.
-
#sync_hosts ⇒ TrueClass, FalseClass
When set to true, running the hosts provisioner on this VM will update all other running machines that use the hosts provisioner.
Instance Method Summary collapse
-
#add_host(address, aliases) ⇒ Object
Register a host for entry.
-
#add_ipv6_multicast ⇒ Object
All IPv6 multicast addresses.
- #finalize! ⇒ Object
-
#initialize ⇒ Config
constructor
A new instance of Config.
-
#merge(other) ⇒ VagrantHosts::Config
The merged results.
- #validate(machine) ⇒ Object
Constructor Details
#initialize ⇒ Config
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_hostnames ⇒ TrueClass, FalseClass
19 20 21 |
# File 'lib/vagrant-hosts/config.rb', line 19 def add_localhost_hostnames @add_localhost_hostnames end |
#autoconfigure ⇒ TrueClass, FalseClass
13 14 15 |
# File 'lib/vagrant-hosts/config.rb', line 13 def autoconfigure @autoconfigure end |
#exports ⇒ Hash{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.
35 36 37 |
# File 'lib/vagrant-hosts/config.rb', line 35 def exports @exports end |
#hosts ⇒ Object
Returns the value of attribute hosts.
8 9 10 |
# File 'lib/vagrant-hosts/config.rb', line 8 def hosts @hosts end |
#imports ⇒ Array<String>
Returns A list of exports to collect from other VMs.
42 43 44 |
# File 'lib/vagrant-hosts/config.rb', line 42 def imports @imports end |
#sync_hosts ⇒ TrueClass, 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_multicast ⇒ Object
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 |