# Has anyone implemented a failable dependency for Rake?

**URL:** <https://www.ruby-forum.com/t/has-anyone-implemented-a-failable-dependency-for-rake/90729>\
**Category:** Ruby\
**Created:** [March 31, 2007, 4:04pm UTC](https://www.ruby-forum.com/t/has-anyone-implemented-a-failable-dependency-for-rake/90729 "2007-03-31T16:04:54Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![lfast](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/ee59a6/32.png) [@lfast](https://www.ruby-forum.com/u/lfast)\
**Post date:** [March 31, 2007, 4:04pm UTC](https://www.ruby-forum.com/t/has-anyone-implemented-a-failable-dependency-for-rake/90729/1 "2007-03-31T16:04:54Z")

</div>

What I find myself writing in Rake is the following:

task xyz =\> [‘abc?’] do  
enc

# test before proceeding

task abc? do  
if !abc  
exit  
end  
end

What I’m creating is failable dependencies. XYZ should not be executed  
unless abc succeeds. Unfortunately the structure I’ve shown stops on  
the first failure. What I’d like to do is report all failures but only  
execute if everything passes.

This could be implemented by processing prerequisites until a prereq  
returns false. Any task containing any false prereqs would not be  
processed.

Does this exist anywhere?

Thanks,  
Larry F.

---

<div class="post-metadata">

**Author:** ![lfast](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/ee59a6/32.png) [@lfast](https://www.ruby-forum.com/u/lfast)\
**Post date:** [April 1, 2007, 2:58am UTC](https://www.ruby-forum.com/t/has-anyone-implemented-a-failable-dependency-for-rake/90729/2 "2007-04-01T02:58:39Z")

</div>

Larry F. wrote:

> What I find myself writing in Rake is the following:
> 
> task xyz =\> [‘abc?’] do  
> enc
> 
> # test before proceeding
> 
> task abc? do  
> if !abc  
> exit  
> end  
> end
> 
> What I’m creating is failable dependencies. XYZ should not be executed  
> unless abc succeeds. Unfortunately the structure I’ve shown stops on  
> the first failure. What I’d like to do is report all failures but only  
> execute if everything passes.
> 
> This could be implemented by processing prerequisites until a prereq  
> returns false. Any task containing any false prereqs would not be  
> processed.
> 
> Does this exist anywhere?

It’s not directly supported by Rake.

The way I think I would approach this is to let each of the  
prerequisites vote on whether the xyz task should run or not. The  
prereqs would register the voting with in some central location (e.g. a  
global or maybe some central voting object). I would then write the xyz  
task like this:

task :xyz =\> [:abc?, :acb?] do  
if XYZ\_SHOULD\_RUN.ok?  
do\_xyz\_stuff  
end  
end

This way all the prerequisites get a chance to run and the xyz task is  
responsible for detecting the vote.

– Jim W.

---

<div class="post-metadata">

**Author:** ![lfast](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/ee59a6/32.png) [@lfast](https://www.ruby-forum.com/u/lfast)\
**Post date:** [April 1, 2007, 3:57am UTC](https://www.ruby-forum.com/t/has-anyone-implemented-a-failable-dependency-for-rake/90729/3 "2007-04-01T03:57:50Z")

</div>

Jim W. wrote:

> The way I think I would approach this is to let each of the  
> prerequisites vote on whether the xyz task should run or not. The  
> prereqs would register the voting with in some central location (e.g. a  
> global or maybe some central voting object). I would then write the xyz  
> task like this:
> 
> task :xyz =\> [:abc?, :acb?] do  
> if XYZ\_SHOULD\_RUN.ok?  
> do\_xyz\_stuff  
> end  
> end
> 
> This way all the prerequisites get a chance to run and the xyz task is  
> responsible for detecting the vote.
> 
> – Jim W.

That’s one step in the right direction but I have a few dozen of these.  
I’d like to inherit and extend the Rake::Task so I could write all my  
tasks as:

task\_failable :xyz =\> […]

Each action would be attempted only if no dependency had failed. BUT all  
the failures would be reported.

This would be most important in a long build process. You walk away  
hoping it will complete. The next morning, most of it has completed and  
you can follow up on the errors. I suspect that’s what file\_tasks do  
but I have some non-file based testing to do.

On the other hand, I may have just talked myself out of this approach.  
It may be easier to create files to represent the completion of these  
actions.

Thanks,  
Larry F.
