What is the correct way to use CLEAN rake task?

This is what I am 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's the right way?

+3


source to share


2 answers


'rake/clean'

already defines a constant CLEAN

as follows: CLEAN = ::Rake::FileList["**/*~", "**/*.bak", "**/core"]

. Constants are not meant to be overridden (although ruby ​​will allow you). If you want to specify the files to be cleaned up, you must create your own rake task similar to the existing one.

The existing task is in progress:

Rake::Cleaner.cleanup_files(CLEAN)

      



So, you can run:

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

      

to clear your coverage files.

+5


source


CLEAN

- FileList

which is used by a predefined task CLEAN

. To add your own cleanup files, add them to this list. You can use the method include

:

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

      



Now running rake clean

will delete your files as well as a predefined set of temporary files if they have a bean.

+9


source







All Articles