views:

302

answers:

2

I have a rake task file for a RubyOnRails app which resides in the lib/tasks directory. Running [rake db:migrate VERSION=0] seems to force the compiler to check syntax in the lib/tasks files. If there is a file with bad syntax then [rake db:migrate] does not run. Why? So what if I have a bad file in lib/tasks. What is happening here? Thanks.

+1  A: 

When Rake runs, it automatically loads all .rake files in your lib/tasks folder. When it loads those tasks, if you have a syntax error, it will be caught.

erik
How do you know this? Is there some documentation that talks about this?
fooledbyprimes
It's in the Rails documentation somewhere. It is one of the convention over configuration rules that Rails uses.
erik
So are you saying that when I run the rake utility that comes with rails that it is a version of rake that has been tweeked to provide rails related conventions?
fooledbyprimes
The Rake that comes with Rails is not a different version. The Rakefile in your app root instructs Rake which files to load.
erik
+2  A: 

When rake runs, it loads all .rake files in lib/tasks before it looks for the task it was instructed to run. It loads all the files, rather than stopping when it finds the task it wants, because tasks can be overridden by files later in the load order.

You can avoid having them all loaded by specifying the rakefile you want:

rake mytask --rakefile lib/my_task.rake
Sarah Mei