4

This is what I'm trying to do in my Rakefile:

require 'rake/clean'
CLEAN = ['coverage']

This is what I see in the log:

$ rake
/code/foo/Rakefile:29: warning: already initialized constant CLEAN
/Users/foo/.rvm/gems/ruby-2.1.3/gems/rake-10.3.2/lib/rake/clean.rb:61: warning: previous definition of CLEAN was here

I don't like these warnings.. What is the right way?

Bernie Noel
  • 304
  • 2
  • 10

2 Answers2

13

CLEAN is a FileList that is used by the predefined clean task. To add your own files to be cleaned, add them to this list. You can use the include method:

require 'rake/clean'
CLEAN.include 'coverage'

Now running rake clean will remove your files, as well as the predefined set of temporary files if any have bean created.

matt
  • 78,533
  • 8
  • 163
  • 197
4

'rake/clean' already defines the constant CLEAN like so: CLEAN = ::Rake::FileList["**/*~", "**/*.bak", "**/core"]. Constants aren't meant to be overridden (although ruby will let you). If you want to specify the files to be cleaned, you should create your own rake task similar the existing one.

The existing task runs:

Rake::Cleaner.cleanup_files(CLEAN)

So you could run:

Rake::Cleaner.cleanup_files(['coverage'])

to clean up your coverage files.

ptd
  • 3,024
  • 16
  • 29
  • if `coverage` is a directory and you want to cleanup everything in it you can also pass `Rake::Cleaner.cleanup_files` a `FileList`: `Rake::Cleaner.cleanup_files(FileList['coverage/**/*'])` – mbigras Dec 31 '16 at 18:17