Where are rake tasks defined? Where are rake tasks defined? ruby ruby

Where are rake tasks defined?


If by described you mean defined, rake -W is your friend. Example:

$ rake -W db:create

=>

rake db:create  /path/to/ruby/gems/1.9.1/gems/activerecord-3.1.11/lib/active_record/railties/databases.rake:39:in `block in <top (required)>'

Just found this out today :)


Rake tasks are automatically loaded from the folder structure lib/tasks/*.rake

When we are talking about the task db:migrate for example, it is located within the rails gem in lib/tasks/databases.rake

So for a specific project, you will always have the tasks within the project folder structure as well as all tasks within the specified gems.


To find the specific files and line numbers where a task is defined and/or modified, do this:

Start a rails console:

rails c

Then run these commands:

require 'rake'Rake::TaskManager.record_task_metadata=trueRake.application.load_rakefiletsk = Rake.application.tasks.find {|t| t.name =='my_task_name'}tsk.locations

Rake basically can track the locations internally and has a nifty method to show them upon request. The above code basically loads rake, tells Rake to track the file locations, loads the Rakefile (and all other included ones), finds the task in question, and calls the locations method on it.

From sameers comment, for rake v 10.1.0 and possibly older versions of rake you might have to call: tsk.actionsinstead of tsk.locations