lib/vagrant-hosts/config.rb in vagrant-hosts-1.1.1 vs lib/vagrant-hosts/config.rb in vagrant-hosts-1.1.2

- old
+ new

@@ -1,62 +1,66 @@ require 'vagrant' module VagrantHosts -class Config < Vagrant.plugin('2', :config) + class Config < Vagrant.plugin('2', :config) - # @!attribute hosts - # @return [Array<Array<String, Array<String>>>] A list of IP addresses and their aliases - attr_reader :hosts + # @!attribute hosts + # @return [Array<Array<String, Array<String>>>] A list of IP addresses and their aliases + attr_reader :hosts - # @!attribute autoconfigure - # @return [TrueClass, FalseClass] If hosts should be generated from the - # other vagrant machines - attr_accessor :autoconfigure + # @!attribute autoconfigure + # @return [TrueClass, FalseClass] If hosts should be generated from the + # other vagrant machines + attr_accessor :autoconfigure - def initialize - @hosts = [] - @autoconfigure = UNSET_VALUE - end + def initialize + @hosts = [] + @autoconfigure = UNSET_VALUE + end - # Register a host for entry - # - # @param [String] address The IP address for aliases - # @param [Array] aliases An array of hostnames to assign to the IP address - def add_host(address, aliases) - @hosts << [address, aliases] - end + # Register a host for entry + # + # @param [String] address The IP address for aliases + # @param [Array] aliases An array of hostnames to assign to the IP address + def add_host(address, aliases) + @hosts << [address, aliases] + end - # All IPv6 multicast addresses - 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 - - def finalize! - if @autoconfigure == UNSET_VALUE or @hosts.empty? - @autoconfigure = true + # All IPv6 multicast addresses + 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 - end - # @param other [VagrantHosts::Config] - # @return [VagrantHosts::Config] The merged results - def merge(other) - super.tap do |result| - result.hosts += other.hosts + def finalize! + if @autoconfigure == UNSET_VALUE + if @hosts.empty? + @autoconfigure = true + else + @autoconfigure = false + end + end end - end - 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}" + # @param other [VagrantHosts::Config] + # @return [VagrantHosts::Config] The merged results + def merge(other) + super.tap do |result| + result.hosts += other.hosts end end - {"Vagrant Hosts" => errors} + 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 end -end end