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.
views:
302answers:
2
+1
Q:
Why does initation of [rake db:migrate] run syntax check on rake tasks in the lib/tasks directory?
+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
2009-03-04 16:03:44
How do you know this? Is there some documentation that talks about this?
fooledbyprimes
2009-03-04 16:07:06
It's in the Rails documentation somewhere. It is one of the convention over configuration rules that Rails uses.
erik
2009-03-04 16:23:34
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
2009-03-06 00:23:12
The Rake that comes with Rails is not a different version. The Rakefile in your app root instructs Rake which files to load.
erik
2009-03-06 15:37:09
+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
2009-03-04 22:47:39