Class: Trash

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Trash

Returns a new instance of Trash.



7
8
9
10
11
# File 'lib/trash.rb', line 7

def initialize(options = {})
  @trash_can = options[:trash_can].nil? ? "#{ENV['HOME']}/.Trash" : options[:trash_can]
  create_trash_can_if_absent
  @errors = []
end

Instance Attribute Details

#errorsObject (readonly)

Returns the value of attribute errors.



4
5
6
# File 'lib/trash.rb', line 4

def errors
  @errors
end

#trash_canObject

Returns the value of attribute trash_can.



5
6
7
# File 'lib/trash.rb', line 5

def trash_can
  @trash_can
end

Instance Method Details

#add_error(error) ⇒ Object



31
32
33
# File 'lib/trash.rb', line 31

def add_error(error)
  @errors << error
end

#has_trash_can?Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/trash.rb', line 13

def has_trash_can?
  File.directory? @trash_can 
end

#throw_out(*paths) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/trash.rb', line 17

def throw_out(*paths)
  paths.each do |path|
    path = File.expand_path(path)
    if File.exist? path
      FileUtils.mv(path, "#{@trash_can}/#{unique_file_name(path)}")
    else
      add_error "#{path} does not exist.  Please check the file path."
      return 1
    end
  end
  
  return 0
end