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,
  :host_interface            => nil,
  :host_interface_excludes   => [/lo[0-9]*/, /docker[0-9]+/, /tun[0-9]+/],
  :host_redirect_dns         => true
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfig

Returns a new instance of Config.



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

def initialize
  @hosts                     = {}
  @enabled                   = UNSET_VALUE
  @tld                       = UNSET_VALUE
  @upstream_servers          = UNSET_VALUE
  @host_ip_address           = UNSET_VALUE
  @guest_redirect_dns        = UNSET_VALUE
  @host_interface            = UNSET_VALUE
  @host_interface_excludes   = UNSET_VALUE
  @host_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_interfaceObject

Returns the value of attribute host_interface.



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

def host_interface
  @host_interface
end

#host_interface_excludesObject

Returns the value of attribute host_interface_excludes.



10
11
12
# File 'lib/landrush/config.rb', line 10

def host_interface_excludes
  @host_interface_excludes
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

#host_redirect_dnsObject

Returns the value of attribute host_redirect_dns.



11
12
13
# File 'lib/landrush/config.rb', line 11

def host_redirect_dns
  @host_redirect_dns
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



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

def disable
  @enabled = false
end

#enableObject



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

def enable
  @enabled = true
end

#enabled?Boolean

Returns:

  • (Boolean)


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

def enabled?
  !!@enabled
end

#finalize!Object



79
80
81
82
83
84
85
# File 'lib/landrush/config.rb', line 79

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)


48
49
50
# File 'lib/landrush/config.rb', line 48

def guest_redirect_dns?
  @guest_redirect_dns
end

#host(hostname, ip_address = nil) ⇒ Object



56
57
58
# File 'lib/landrush/config.rb', line 56

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

#host_redirect_dns?Boolean

Returns:

  • (Boolean)


52
53
54
# File 'lib/landrush/config.rb', line 52

def host_redirect_dns?
  @host_redirect_dns
end

#merge(other) ⇒ Object



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

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

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



60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/landrush/config.rb', line 60

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



87
88
89
90
# File 'lib/landrush/config.rb', line 87

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