简体   繁体   中英

what is the right way to use CLEAN rake task?

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?

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.

'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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM