I am basically trying to convert a solution to this question into a rake task: How do I find the source file for a rake task?
I want to type, e.g.:
rake meta:where[test]
And get the path where the test task is defined. Here's what I have, with some unnecessary stuff so I can make some relevant comments:
Rake::TaskManager.record_task_metadata=true
namespace :meta do
desc "meta:where[taskname] - where is taskname defined?"
task :where, [:taskname] do |t, args|
tsk = Rake.application.tasks.each.find {|t| t.name == args.taskname}
puts tsk
tsk.locations.each {|x| puts x}
end
end
So, puts tsk actually outputs 'test', which means (I think!) I'm correctly locating the task here. It's no trouble printing the path from the rails console using the same code (as in the above-mentioned SO post). It says something like:
/Users/me/.rvm/gems/ruby-1.9.3-p362/gems/railties-3.2.11/lib/rails/test_unit/testing.rake:49:in `<top (required)>'
Any idea how I can get the location(s) to print?