Class: Musicality::Tasks::FileCleaner

Inherits:
Rake::TaskLib
  • Object
show all
Defined in:
lib/musicality/project/file_cleaner.rb

Instance Method Summary collapse

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