Skip to content

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

@bmundt6

Description

@bmundt6

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions