class Kellerkind::LogFile

Public: Compresses/Backups a bunch of files. All methods are module methods and should be called on the Math module.

Public Instance Methods

archive() click to toggle source

Public: Compresses the backup, removes the files and (optional) recreates them as blank files.

# File lib/kellerkind/modules/implementations/log_file.rb, line 20
def archive
  files.each do |path|
    path_obj  = Pathname.new(path)
    path_name = path_obj.dirname.to_s
    compress  = Kellerkind::Compress.new(:target_path => out,
                                         :source_path => path,
                                         :tarball_prefix => path_obj.basename.to_s)
    compress.find_at_source_path = true
    if File.exists?(path)
      Kellerkind::Process.verbose(:start_compressing)
      compress.gzip
      if File.exists?("#{path_name}/#{compress.tarball_name}")
        Kellerkind::Process.verbose(:finished_compressing)
        FileUtils.mv("#{path_name}/#{compress.tarball_name}",
                   "#{out}/#{compress.tarball_name}")
        FileUtils.rm_rf(path)
        FileUtils.touch(path) if self.recreate
      end
    end
  end
end