class Nito::Hostname

Public Class Methods

new(hostname) click to toggle source
# File lib/nito/hostname.rb, line 5
def initialize(hostname)
  @hostname = hostname
  @hostname_file = '/etc/hostname'
  @hosts_file = '/etc/hosts'
  new
end

Private Instance Methods

new() click to toggle source
# File lib/nito/hostname.rb, line 14
def new
  tmp = Tempfile.new('hostname')
  File.write(tmp, @hostname)
  Nito::Cp.new(tmp.path, @hostname_file)
  reg_1 = /^127.0.0.1[\s]+localhost/
  reg_2 = /^::1[\s]+localhost/
  Nito::Sed.new(@hosts_file, reg_1, "127.0.0.1 localhost #{@hostname}")
  Nito::Sed.new(@hosts_file, reg_2, "::1 localhost #{@hostname}")
end