Module: Trash
- Defined in:
- lib/trash.rb,
lib/trash/version.rb
Overview
Namespace for system file’s trash.
Constant Summary collapse
- VERSION =
'1.0.1'
Class Method Summary collapse
-
.empty ⇒ Object
Empty the trash.
-
.list ⇒ Object
List trashed files.
-
.put(*paths) ⇒ Object
Put files in trash.
Class Method Details
.empty ⇒ Object
Empty the trash.
83 84 85 86 87 88 89 90 91 |
# File 'lib/trash.rb', line 83 def empty make_trash_paths [TRASH_FILE_PATH, TRASH_INFO_PATH] .map { Dir.children _1 }.flatten .each { FileUtils.remove_entry_secure _1, force: true } nil end |
.list ⇒ Object
List trashed files.
59 60 61 62 63 64 65 |
# File 'lib/trash.rb', line 59 def list make_trash_paths Dir.chdir TRASH_FILE_PATH do Dir.children('.').map { Entry.new _1 }.select { _1.origin && _1.dtime }.sort_by(&:dtime) end end |
.put(*paths) ⇒ Object
Put files in trash.
68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/trash.rb', line 68 def put(*paths) make_trash_paths paths.flatten.map do |path| trash_name = trash_name(path) trash_path = File.join(TRASH_FILE_PATH, trash_name) FileUtils.move(path, trash_path, secure: true) make_trash_info(path, trash_name) Entry.new trash_path end end |