You can do this by stretching a bit:
Rakefile:
require File.join(File.dirname(__FILE__), 'unfile_rake_ext') unfile 'target.txt' do File.delete('target.txt') end
unfile_rake_ext.rb:
class UnFileTask < Rake::FileTask def needed? File.exist?(name) end end def unfile(*args, &block) UnFileTask.define_task(*args, &block) end
And my console output:
D:\Projects\ZPersonal\tmp>ls Rakefile unfile_rake_ext.rb D:\Projects\ZPersonal\tmp>touch target.txt && ls Rakefile target.txt unfile_rake_ext.rb D:\Projects\ZPersonal\tmp>rake target.txt --trace ** Invoke target.txt (first_time) ** Execute target.txt D:\Projects\ZPersonal\tmp>ls Rakefile unfile_rake_ext.rb D:\Projects\ZPersonal\tmp>rake target.txt --trace ** Invoke target.txt (first_time, not_needed) D:\Projects\ZPersonal\tmp>ls Rakefile unfile_rake_ext.rb
Hope this helps.
source share