Is it possible from within a rake task to get a list of tasks in a namespace? A sort of programatic 'rake -T db' ?
You can get a list of Rake tasks available to you, which will often depend on your current directory, by typing rake --tasks . Each task has a description, and should help you find the thing you need.
How to Write a Rake Task. You can put this code inside a file named Rakefile , or if you're using Rails, you can save this under lib/tasks/apple. rake .
rake is a Make-like program implemented in Ruby. rails is a web framework, which also has some rake tasks. This means that you can have a ruby program with rake but without rails, but not the other way around. By itself, rake will be faster because you don't need to load the whole rails application.
Including => :environment will tell Rake to load full the application environment, giving the relevant task access to things like classes, helpers, etc. Without the :environment , you won't have access to any of those extras.
I've found out the answer:
tasks = Rake.application.tasks
This will return an array of Rake::Task objects that can be examined. Further details at http://rake.rubyforge.org/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With