Class: VagrantPlugins::HostManager::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant-hostmanager/config.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfig

Returns a new instance of Config.



15
16
17
18
19
20
21
22
# File 'lib/vagrant-hostmanager/config.rb', line 15

def initialize
  @enabled            = UNSET_VALUE
  @manage_host        = UNSET_VALUE
  @ignore_private_ip  = UNSET_VALUE
  @include_offline    = UNSET_VALUE
  @aliases            = UNSET_VALUE
  @ip_resolver        = UNSET_VALUE
end

Instance Attribute Details

#aliasesObject

Returns the value of attribute aliases.



7
8
9
# File 'lib/vagrant-hostmanager/config.rb', line 7

def aliases
  @aliases
end

#enabledObject Also known as: enabled?

Returns the value of attribute enabled.



4
5
6
# File 'lib/vagrant-hostmanager/config.rb', line 4

def enabled
  @enabled
end

#ignore_private_ipObject

Returns the value of attribute ignore_private_ip.



6
7
8
# File 'lib/vagrant-hostmanager/config.rb', line 6

def ignore_private_ip
  @ignore_private_ip
end

#include_offlineObject Also known as: include_offline?

Returns the value of attribute include_offline.



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

def include_offline
  @include_offline
end

#ip_resolverObject

Returns the value of attribute ip_resolver.



9
10
11
# File 'lib/vagrant-hostmanager/config.rb', line 9

def ip_resolver
  @ip_resolver
end

#manage_hostObject Also known as: manage_host?

Returns the value of attribute manage_host.



5
6
7
# File 'lib/vagrant-hostmanager/config.rb', line 5

def manage_host
  @manage_host
end

Instance Method Details

#finalize!Object



24
25
26
27
28
29
30
31
32
33
# File 'lib/vagrant-hostmanager/config.rb', line 24

def finalize!
  @enabled            = false if @enabled == UNSET_VALUE
  @manage_host        = false if @manage_host == UNSET_VALUE
  @ignore_private_ip  = false if @ignore_private_ip == UNSET_VALUE
  @include_offline    = false if @include_offline == UNSET_VALUE
  @aliases            = [] if @aliases == UNSET_VALUE
  @ip_resolver        = nil if @ip_resolver == UNSET_VALUE

  @aliases = [ @aliases ].flatten
end

#validate(machine) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/vagrant-hostmanager/config.rb', line 35

def validate(machine)
  errors = []

  errors << validate_bool('hostmanager.enabled', @enabled)
  errors << validate_bool('hostmanager.manage_host', @manage_host)
  errors << validate_bool('hostmanager.ignore_private_ip', @ignore_private_ip)
  errors << validate_bool('hostmanager.include_offline', @include_offline)
  errors.compact!

  # check if aliases option is an Array
  if  !machine.config.hostmanager.aliases.kind_of?(Array) &&
      !machine.config.hostmanager.aliases.kind_of?(String)
    errors << I18n.t('vagrant_hostmanager.config.not_an_array_or_string', {
      :config_key => 'hostmanager.aliases',
      :is_class   => aliases.class.to_s,
    })
  end

  if !machine.config.hostmanager.ip_resolver.nil? &&
     !machine.config.hostmanager.ip_resolver.kind_of?(Proc)
    errors << I18n.t('vagrant_hostmanager.config.not_a_proc', {
      :config_key => 'hostmanager.ip_resolver',
      :is_class   => ip_resolver.class.to_s,
    })
  end

  errors.compact!
  { "HostManager configuration" => errors }
end