Class: VagrantHosts::Config
- Inherits:
-
Object
- Object
- VagrantHosts::Config
- Defined in:
- lib/vagrant-hosts/config.rb
Instance Attribute Summary collapse
-
#autoconfigure ⇒ TrueClass, FalseClass
If hosts should be generated from the other vagrant machines.
-
#hosts ⇒ Object
Returns the value of attribute hosts.
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
Returns a new instance of Config.
15 16 17 18 |
# File 'lib/vagrant-hosts/config.rb', line 15 def initialize @hosts = [] @autoconfigure = UNSET_VALUE end |
Instance Attribute Details
#autoconfigure ⇒ TrueClass, FalseClass
Returns 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 |
#hosts ⇒ Object
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
24 25 26 |
# File 'lib/vagrant-hosts/config.rb', line 24 def add_host(address, aliases) @hosts << [address, aliases] end |
#add_ipv6_multicast ⇒ Object
All IPv6 multicast addresses
29 30 31 32 33 34 35 |
# File 'lib/vagrant-hosts/config.rb', line 29 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
37 38 39 40 41 42 43 44 45 |
# File 'lib/vagrant-hosts/config.rb', line 37 def finalize! if @autoconfigure == UNSET_VALUE if @hosts.empty? @autoconfigure = true else @autoconfigure = false end end end |
#merge(other) ⇒ VagrantHosts::Config
Returns The merged results.
49 50 51 52 53 |
# File 'lib/vagrant-hosts/config.rb', line 49 def merge(other) super.tap do |result| result.hosts += other.hosts end end |
#validate(machine) ⇒ Object
55 56 57 58 59 60 61 62 63 64 |
# File 'lib/vagrant-hosts/config.rb', line 55 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 |