Friday, February 6, 2009

Rake and class variables

I wrote a set of Rake task recently. To allow them to form a basis for future expansion, I broke them down into parts and used a class variable to hold state, since I could not pass parameters between them.

It appears that in moving to the version of Rake with Rails 2.1 that the global variables are lost at the end of each task.

I was able to re-factor the code to use a common method for re-use. However, the re-use is limited. I can call the common method from each task. However the tasks can not depend on one another since the state cannot be persisted between them.

This change made Rake tasks less useful - to me at least.