Class: VagrantDns::ResolvConf

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant_dns/resolver.rb

Instance Method Summary collapse

Instance Method Details

#appendObject



24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/vagrant_dns/resolver.rb', line 24

def append()
  input =  IO.readlines(RESOLV)
  ns_pos = input.find_index do |line|
    line.include?('nameserver')
  end

  if(!local_defined?(input,ns_pos))
    head = (input.slice(0,ns_pos) << LOCAL)
    tail = input.slice(ns_pos,input.size)
    newconf = head.concat(tail).join('')
    atomic_write(RESOLV,newconf)
  end
end

#clearObject



38
39
40
41
42
# File 'lib/vagrant_dns/resolver.rb', line 38

def clear
  input = IO.readlines(RESOLV)
  cleaned = input.select{|line| !line.eql?(LOCAL)}.join('')
  atomic_write(RESOLV,cleaned)
end

#local_defined?(input, pos) ⇒ Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/vagrant_dns/resolver.rb', line 44

def local_defined?(input,pos)
  input[pos].eql?(LOCAL.chomp)
end