Class: Trash
- Inherits:
-
Object
- Object
- Trash
- Defined in:
- lib/trash.rb
Instance Attribute Summary collapse
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
-
#trash_can ⇒ Object
Returns the value of attribute trash_can.
Instance Method Summary collapse
- #add_error(error) ⇒ Object
- #has_trash_can? ⇒ Boolean
-
#initialize(options = {}) ⇒ Trash
constructor
A new instance of Trash.
- #throw_out(*paths) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Trash
Returns a new instance of Trash.
7 8 9 10 11 |
# File 'lib/trash.rb', line 7 def initialize( = {}) @trash_can = [:trash_can].nil? ? "#{ENV['HOME']}/.Trash" : [:trash_can] create_trash_can_if_absent @errors = [] end |
Instance Attribute Details
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
4 5 6 |
# File 'lib/trash.rb', line 4 def errors @errors end |
#trash_can ⇒ Object
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
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.(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 |