Sha256: 6472a6a4410fb1879d5cdd06dfde70e23b6b2fe9bfac03e152defcf4cf9e8b6f
Contents?: true
Size: 783 Bytes
Versions: 25
Compression:
Stored size: 783 Bytes
Contents
module LinuxAdmin class Dns attr_accessor :filename attr_accessor :nameservers attr_accessor :search_order def initialize(filename = "/etc/resolv.conf") @filename = filename reload end def reload @search_order = [] @nameservers = [] File.read(@filename).split("\n").each do |line| if line =~ /^search .*/ @search_order += line.split(/^search\s+/)[1].split elsif line =~ /^nameserver .*/ @nameservers.push(line.split[1]) end end end def save search = "search #{@search_order.join(" ")}\n" unless @search_order.empty? servers = @nameservers.collect { |ns| "nameserver #{ns}\n" }.join File.write(@filename, "#{search}#{servers}") end end end
Version data entries
25 entries across 25 versions & 1 rubygems