What is the new format for rake tasks? (task :t, arg, :needs => [deps] versus task :t, [args] => [deps])

孤街醉人 提交于 2019-12-04 16:53:08

问题


I'm using Rails 3.1 beta with Ruby 1.9.2 and rake 0.9.2, and have a bunch of rake tasks I've written. Here is an example:

namespace :data do
  desc "dump the nodes and edges for a graph"
  task :dump_graph, :species_id, :needs => :environment do |t,args|
    args.with_defaults(:species_id => 'Hs')
    # ...
  end
end

When my rails app loads these rake tasks, however, I now get the following warning repeated once for each rake task:

    at /home/user/railsapp/lib/tasks/data/dump_graph.rake:3:in `block in <top (required)>'
WARNING: 'task :t, arg, :needs => [deps]' is deprecated.  Please use 'task :t, [args] => [deps]' instead.

I've experimented with rearranging the arguments in several different ways, but I'm not clear on exactly what my task should look like now.

Does rake expect me to give the individual dependencies? How do I define these in a rake task if the dep is the rails environment?

A link to updated documentation would be an acceptable answer! I've Googled and Googled, but no luck.

(And yes, I realize that the format is given in the error message. But that format does not appear to be correct, based on the variations I've tried.)


回答1:


I know it is sometimes hard to decipher but the error message gives you the new format:

task :t, [args] => [deps]

So for your example:

task :dump_graph, :species_id => :environment

http://www.postal-code.com/binarycode/2011/06/02/rake-needs-deprecated/




回答2:


The usage which works for me is:

task :task_name, [:argument] => :environment

I guess if you had several dependencies to list, deps would need the array notation.

I've no idea why a single argument requires the array notation - running the rake task with --trace gives an error about the :argument symbol not responding to the empty? method.



来源:https://stackoverflow.com/questions/6270671/what-is-the-new-format-for-rake-tasks-task-t-arg-needs-deps-versus-ta

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!