class GdnsdIo::FileOperations

Public Class Methods

new(*args) click to toggle source
# File lib/gdnsd_io/file_operations.rb, line 3
def initialize(*args)
        options = args.last.is_a?(Hash) ? args.pop : {}
    @config = GdnsdIo::FilePath.new options
end

Public Instance Methods

create_text(text_file_name) click to toggle source
# File lib/gdnsd_io/file_operations.rb, line 20
def create_text(text_file_name)
        tmp_file = File.new(@config.filepath + "/" + text_file_name + ".txt", "w+") unless File.exists?(text_file_name)
        tmp_file.close
end
delete_text(text_file_name) click to toggle source
# File lib/gdnsd_io/file_operations.rb, line 25
def delete_text(text_file_name)
        File.delete(@config.filepath + "/" + text_file_name + ".txt")
end
write_record(records, text_file_name) click to toggle source
# File lib/gdnsd_io/file_operations.rb, line 8
def write_record(records, text_file_name)
    tmp_file = File.new(@config.filepath + "/" + text_file_name + ".txt", "w+") unless File.exists?(text_file_name)
        records.each do |record|
                if record[:prio].nil?
              tmp_file.puts(record[:name].to_s + " \t" + record[:rtype].to_s + "\t" + record[:content].to_s + "\t" + record[:ttl].to_s )
      else
              tmp_file.puts(record[:name].to_s + " \t" + record[:rtype].to_s + "\t" + record[:content].to_s + "\t" + record[:ttl].to_s + " \t" + record[:prio].to_s )
                end
        end
        tmp_file.close
end