Class: OSXTrash

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

Instance Method Summary collapse

Constructor Details

#initializeOSXTrash

Returns a new instance of OSXTrash.



9
10
11
# File 'lib/osxtrash.rb', line 9

def initialize
    @finder = create_finder
end

Instance Method Details

#delete(files) ⇒ Object



24
25
26
27
28
29
30
31
32
33
# File 'lib/osxtrash.rb', line 24

def delete(files)
    files = [ files ] if files.kind_of? String
    files.each do |file|
        path = Pathname.new(file)
        url = NSURL.fileURLWithPath(path.realpath.to_s)
        item = @finder.items.objectAtLocation(url)
        item.delete
    end
    return
end

#listObject



13
14
15
16
17
18
19
20
21
22
# File 'lib/osxtrash.rb', line 13

def list
    items = []
    trash = @finder.trash
    trash.items.each do |item|
        file_url = NSURL.URLWithString(item.URL)
        Pathname item_path = Pathname.new(file_url.path) # really needed?
        items << item_path.to_s
    end
    return items
end