class Landrush::Config

Constants

DEFAULTS
INTERFACE_CLASSES
INTERFACE_CLASS_INVALID

Attributes

enabled[RW]
guest_redirect_dns[RW]
host_interface[RW]
host_interface_class[RW]
host_interface_excludes[RW]
host_ip_address[RW]
host_redirect_dns[RW]
hosts[RW]
tld[RW]
upstream_servers[RW]

Public Class Methods

new() click to toggle source
# File lib/landrush/config.rb, line 29
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_interface_class      = UNSET_VALUE
  @host_redirect_dns         = UNSET_VALUE
end

Public Instance Methods

disable() click to toggle source
# File lib/landrush/config.rb, line 46
def disable
  @enabled = false
end
enable() click to toggle source
# File lib/landrush/config.rb, line 42
def enable
  @enabled = true
end
enabled?() click to toggle source
# File lib/landrush/config.rb, line 50
def enabled?
  !!@enabled
end
finalize!() click to toggle source
# File lib/landrush/config.rb, line 87
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?() click to toggle source
# File lib/landrush/config.rb, line 54
def guest_redirect_dns?
  @guest_redirect_dns
end
host(hostname, ip_address = nil) click to toggle source
# File lib/landrush/config.rb, line 62
def host(hostname, ip_address = nil)
  @hosts[hostname] = ip_address
end
host_redirect_dns?() click to toggle source
# File lib/landrush/config.rb, line 58
def host_redirect_dns?
  @host_redirect_dns
end
merge(other) click to toggle source
Calls superclass method
# File lib/landrush/config.rb, line 81
def merge(other)
  super.tap do |result|
    result.hosts = @hosts.merge(other.hosts)
  end
end
tld_as_array() click to toggle source
# File lib/landrush/config.rb, line 66
def tld_as_array
  Array(@tld)
end
upstream(ip, port = 53, protocol = nil) click to toggle source
# File lib/landrush/config.rb, line 70
def upstream(ip, port = 53, protocol = nil)
  @upstream_servers = [] if @upstream_servers == UNSET_VALUE

  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) click to toggle source
# File lib/landrush/config.rb, line 95
def validate(_machine)
  errors = _detected_errors
  errors.concat validate_host_interface_class

  { 'landrush' => errors }
end
validate_host_interface_class() click to toggle source
# File lib/landrush/config.rb, line 102
def validate_host_interface_class
  @host_interface_class = @host_interface_class.intern if @host_interface_class.is_a? String

  return [] if INTERFACE_CLASSES.include? @host_interface_class

  # TODO: Should really be using I18n; makes testing a lot cleaner too.
  [INTERFACE_CLASS_INVALID, fields: 'host_interface_class']
end