Class: Landrush::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/landrush/config.rb

Constant Summary collapse

DEFAULTS =
{
  :enabled => false,
  :tld => 'vagrant.test',
  :upstream_servers => [[:udp, '8.8.8.8', 53], [:tcp, '8.8.8.8', 53]],
  :host_ip_address => nil,
  :guest_redirect_dns => true
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfig

Returns a new instance of Config.



18
19
20
21
22
23
24
25
# File 'lib/landrush/config.rb', line 18

def initialize
  @hosts = {}
  @enabled = UNSET_VALUE
  @tld = UNSET_VALUE
  @upstream_servers = UNSET_VALUE
  @host_ip_address = UNSET_VALUE
  @guest_redirect_dns = UNSET_VALUE
end

Instance Attribute Details

#enabledObject

Returns the value of attribute enabled.



4
5
6
# File 'lib/landrush/config.rb', line 4

def enabled
  @enabled
end

#guest_redirect_dnsObject

Returns the value of attribute guest_redirect_dns.



8
9
10
# File 'lib/landrush/config.rb', line 8

def guest_redirect_dns
  @guest_redirect_dns
end

#host_ip_addressObject

Returns the value of attribute host_ip_address.



7
8
9
# File 'lib/landrush/config.rb', line 7

def host_ip_address
  @host_ip_address
end

#hostsObject

Returns the value of attribute hosts.



3
4
5
# File 'lib/landrush/config.rb', line 3

def hosts
  @hosts
end

#tldObject

Returns the value of attribute tld.



5
6
7
# File 'lib/landrush/config.rb', line 5

def tld
  @tld
end

#upstream_serversObject

Returns the value of attribute upstream_servers.



6
7
8
# File 'lib/landrush/config.rb', line 6

def upstream_servers
  @upstream_servers
end

Instance Method Details

#disableObject



31
32
33
# File 'lib/landrush/config.rb', line 31

def disable
  @enabled = false
end

#enableObject



27
28
29
# File 'lib/landrush/config.rb', line 27

def enable
  @enabled = true
end

#enabled?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/landrush/config.rb', line 35

def enabled?
  !!@enabled
end

#finalize!Object



66
67
68
69
70
71
72
# File 'lib/landrush/config.rb', line 66

def finalize!
  DEFAULTS.each do |name, value|
    if instance_variable_get('@' + name.to_s) == UNSET_VALUE
      instance_variable_set '@' + name.to_s, value
    end
  end
end

#guest_redirect_dns?Boolean

Returns:

  • (Boolean)


39
40
41
# File 'lib/landrush/config.rb', line 39

def guest_redirect_dns?
  @guest_redirect_dns
end

#host(hostname, ip_address = nil) ⇒ Object



43
44
45
# File 'lib/landrush/config.rb', line 43

def host(hostname, ip_address=nil)
  @hosts[hostname] = ip_address
end

#merge(other) ⇒ Object



60
61
62
63
64
# File 'lib/landrush/config.rb', line 60

def merge(other)
  super.tap do |result|
    result.hosts = @hosts.merge(other.hosts)
  end
end

#upstream(ip, port = 53, protocol = nil) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/landrush/config.rb', line 47

def upstream(ip, port=53, protocol=nil)
  if @upstream_servers == UNSET_VALUE
    @upstream_servers = []
  end

  if !protocol
    @upstream_servers.push [:udp, ip, port]
    @upstream_servers.push [:tcp, ip, port]
  else
    @upstream_servers.push [protocol, ip, port]
  end
end

#validate(machine) ⇒ Object



74
75
76
77
# File 'lib/landrush/config.rb', line 74

def validate(machine)
  errors = _detected_errors
  { 'landrush' => errors }
end