Class: LinuxAdmin::Dns
- Inherits:
-
Object
- Object
- LinuxAdmin::Dns
- Defined in:
- lib/linux_admin/dns.rb
Instance Attribute Summary collapse
-
#filename ⇒ Object
Returns the value of attribute filename.
-
#nameservers ⇒ Object
Returns the value of attribute nameservers.
-
#search_order ⇒ Object
Returns the value of attribute search_order.
Instance Method Summary collapse
-
#initialize(filename = "/etc/resolv.conf") ⇒ Dns
constructor
A new instance of Dns.
- #reload ⇒ Object
- #save ⇒ Object
Constructor Details
#initialize(filename = "/etc/resolv.conf") ⇒ Dns
Returns a new instance of Dns.
7 8 9 10 |
# File 'lib/linux_admin/dns.rb', line 7 def initialize(filename = "/etc/resolv.conf") @filename = filename reload end |
Instance Attribute Details
#filename ⇒ Object
Returns the value of attribute filename.
3 4 5 |
# File 'lib/linux_admin/dns.rb', line 3 def filename @filename end |
#nameservers ⇒ Object
Returns the value of attribute nameservers.
4 5 6 |
# File 'lib/linux_admin/dns.rb', line 4 def nameservers @nameservers end |
#search_order ⇒ Object
Returns the value of attribute search_order.
5 6 7 |
# File 'lib/linux_admin/dns.rb', line 5 def search_order @search_order end |
Instance Method Details
#reload ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/linux_admin/dns.rb', line 12 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 |
#save ⇒ Object
25 26 27 28 29 |
# File 'lib/linux_admin/dns.rb', line 25 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 |