ruby / rake

A make-like build utility for Ruby.

Home Page:https://ruby.github.io/rake

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Request: An alternate FileTask that checks whether the file was made

bmundt6 opened this issue · comments

commented

I think the current implementation of the file task makes perfect sense: just trigger a series of actions based on a file's status, in case you don't necessarily want to actually produce that file.

However, in cases where you do want to produce that file, it would be nice to have a separate task type that supports that, i.e. fails if the task actions don't produce the file even when there are no exceptions thrown.

Example:

class Rake::RequiredFileTask < Rake::FileTask                  
  def execute(*args)                                          
    super(*args)                                              
    File.exists?(name) or raise "File #{name} was not created successfully"
  end                                                                      
end                                                                        

module Rake::DSL
  def required_file(*args, &block) # :doc:
    Rake::RequiredFileTask.define_task(*args, &block)
  end                                                
end

Then, if invoked as:

required_file 'a.out' do |t|
  # do nothing
end

an error would be thrown:

rake aborted!
File a.out was not created successfully