Class: Backupsss::BackupDir
- Inherits:
-
Object
- Object
- Backupsss::BackupDir
- Defined in:
- lib/backupsss/backup_dir.rb
Overview
A class for listing and sorting files by mtime
Instance Method Summary collapse
-
#initialize(opts = {}) ⇒ BackupDir
constructor
A new instance of BackupDir.
- #ls ⇒ Object
- #ls_rt ⇒ Object
- #ls_t ⇒ Object
- #rm(file) ⇒ Object
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
#ls ⇒ Object
10 11 12 |
# File 'lib/backupsss/backup_dir.rb', line 10 def ls Dir.entries(@dir).reject { |f| (f == '..' || f == '.') } end |
#ls_rt ⇒ Object
18 19 20 |
# File 'lib/backupsss/backup_dir.rb', line 18 def ls_rt ls_t.reverse end |
#ls_t ⇒ Object
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 |