Class: VagrantAutoDNS::Config

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

Constant Summary collapse

DAEMON_DEFAULT_OPTS =
{
  :working_directory => '.vagrant/autodns',
  :listen_ip => '127.0.0.1',
  :listen_port => 15353,
  :resolver => :system, #Deamon defaults to system
  :db_file => 'autodns.db',
  :enable_ipv6 => true,
}
CLIENT_DEFAULT_OPTS =
{
  :aliases => []
}
DEFAULT_VALUES =
{
  :enabled => false
}.merge(DAEMON_DEFAULT_OPTS).merge(CLIENT_DEFAULT_OPTS)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfig

Returns a new instance of Config.



56
57
58
59
60
61
62
# File 'lib/vagrant-autodns/config.rb', line 56

def initialize
  super
  DEFAULT_VALUES.keys.each do |default_key|
    instance_key = instance_var(default_key)
    instance_variable_set(instance_key, UNSET_VALUE)
  end
end

Instance Attribute Details

#db_fileString

Returns DB File name.

Returns:

  • (String)

    DB File name



37
38
39
# File 'lib/vagrant-autodns/config.rb', line 37

def db_file
  @db_file
end

#enable_ipv6Boolean

Returns Enable ipv6.

Returns:

  • (Boolean)

    Enable ipv6



31
32
33
# File 'lib/vagrant-autodns/config.rb', line 31

def enable_ipv6
  @enable_ipv6
end

#enabledBoolean

Returns:

  • (Boolean)


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

def enabled
  @enabled
end

#listen_ipString

Returns Valid IPV4 address (default 127.0.0.1).

Returns:

  • (String)

    Valid IPV4 address (default 127.0.0.1)



22
23
24
# File 'lib/vagrant-autodns/config.rb', line 22

def listen_ip
  @listen_ip
end

#listen_ipv6String

Returns IPv6 address.

Returns:

  • (String)

    IPv6 address



28
29
30
# File 'lib/vagrant-autodns/config.rb', line 28

def listen_ipv6
  @listen_ipv6
end

#listen_portFixnum

Returns Port number (default 15353).

Returns:

  • (Fixnum)

    Port number (default 15353)



25
26
27
# File 'lib/vagrant-autodns/config.rb', line 25

def listen_port
  @listen_port
end

#resolverString, Array

Returns (default System resolver).

Returns:

  • (String, Array)

    (default System resolver)



19
20
21
# File 'lib/vagrant-autodns/config.rb', line 19

def resolver
  @resolver
end

#working_directoryString

Returns Directory to store data and state.

Returns:

  • (String)

    Directory to store data and state



34
35
36
# File 'lib/vagrant-autodns/config.rb', line 34

def working_directory
  @working_directory
end

Instance Method Details

#alias(*aliases) ⇒ Object



64
65
66
# File 'lib/vagrant-autodns/config.rb', line 64

def alias(*aliases)
  @aliases.concat(aliases)
end

#disableObject



72
73
74
# File 'lib/vagrant-autodns/config.rb', line 72

def disable
  @enabled = false
end

#enableObject



68
69
70
# File 'lib/vagrant-autodns/config.rb', line 68

def enable
  @enabled = true
end

#enabled?Boolean

Returns:

  • (Boolean)


76
77
78
79
# File 'lib/vagrant-autodns/config.rb', line 76

def enabled?
  #Coerce to boolean
  !!@enabled
end

#finalize!Object



81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/vagrant-autodns/config.rb', line 81

def finalize!
  #special handling for working_directory
  expand_working_directory

  DEFAULT_VALUES.each do |default_key, default_value|
    instance_key = instance_var(default_key)
    if instance_variable_get(instance_key) == UNSET_VALUE
      instance_variable_set(instance_key, default_value)
    end
    next unless DAEMON_DEFAULT_OPTS.has_key?(default_key)
    Daemon.send(:instance_variable_set, instance_key, instance_variable_get(instance_key))
  end
end