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.



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

def initialize
  @hosts = []
  @autoconfigure = UNSET_VALUE
end

Instance Attribute Details

#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



24
25
26
# File 'lib/vagrant-hosts/config.rb', line 24

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

#add_ipv6_multicastObject

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.

Parameters:

Returns:



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