Class: Musicality::Tasks::FileCleaner
- Inherits:
-
Rake::TaskLib
- Object
- Rake::TaskLib
- Musicality::Tasks::FileCleaner
- Defined in:
- lib/musicality/project/file_cleaner.rb
Instance Method Summary collapse
-
#initialize(files, dirs) ⇒ FileCleaner
constructor
A new instance of FileCleaner.
Constructor Details
#initialize(files, dirs) ⇒ FileCleaner
Returns a new instance of FileCleaner.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/musicality/project/file_cleaner.rb', line 7 def initialize files, dirs task :clean do if files.any? puts "Deleting files:" files.each do |fname| puts " " + fname File.delete fname end end existing_dirs = dirs.select {|dir| Dir.exist?(dir) } if existing_dirs.any? puts "Deleting dirs:" existing_dirs.each do |dirname| puts " " + dirname begin FileUtils::rm Dir.glob(File.join(dirname, "*")) FileUtils::rmdir dirname rescue => e puts "Error while trying to delete #{dirname}: #{e}" end end end end end |