Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to get a list of all available rake tasks in a namespace?

Tags:

Is it possible from within a rake task to get a list of tasks in a namespace? A sort of programatic 'rake -T db' ?

like image 873
stephenr Avatar asked Aug 05 '10 13:08

stephenr


People also ask

How do I list all rake tasks?

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.

Where to put Rake tasks?

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 .

What is the difference between Rake and Ruby?

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.

What is environment rake task?

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.


1 Answers

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/

like image 135
stephenr Avatar answered Oct 07 '22 21:10

stephenr