Class: Backupsss::BackupDir

Inherits:
Object
  • Object
show all
Defined in:
lib/backupsss/backup_dir.rb

Overview

A class for listing and sorting files by mtime

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ BackupDir

Returns a new instance of BackupDir.



6
7
8
# File 'lib/backupsss/backup_dir.rb', line 6

def initialize(opts = {})
  @dir = opts[:dir]
end

Instance Method Details

#lsObject



10
11
12
# File 'lib/backupsss/backup_dir.rb', line 10

def ls
  Dir.entries(@dir).reject { |f| (f == '..' || f == '.') }
end

#ls_rtObject



18
19
20
# File 'lib/backupsss/backup_dir.rb', line 18

def ls_rt
  ls_t.reverse
end

#ls_tObject



14
15
16
# File 'lib/backupsss/backup_dir.rb', line 14

def ls_t
  ls.sort_by { |f| File.mtime("#{@dir}/#{f}") }
end

#rm(file) ⇒ Object



22
23
24
25
26
27
# File 'lib/backupsss/backup_dir.rb', line 22

def rm(file)
  FileUtils.rm(File.join(@dir, file))
  file
rescue SystemCallError => e
  raise RemovalError, e
end