在Rake任务定义中,如下所示:
desc 'SOME description' task :some_task => :environment do # DO SOMETHING end什么:some_task in task :some_task => :environment意味着什么?
它是在DO SOMETHING部分中调用的方法名称吗?
可以:some_task是描述任务的任意字符串吗?
In Rake task definition, like following:
desc 'SOME description' task :some_task => :environment do # DO SOMETHING endWhat does the :some_task in task :some_task => :environment means?
Is it the method name which will be invoked in the DO SOMETHING part?
Can :some_task be any arbitrary string which describe the task?
最满意答案
实际上,当您创建rake任务时, :some_task是您正在调用的任务的名称。
例如,在这种情况下,您将调用rake some_task
您还可以为任务定义名称空间:
namespace :my_tasks do desc "My first task" task :first_task => :environment do # DO SOMETHING end end然后你将在你的控制台中调用rake my_tasks:first_task 。
希望它能帮助你,
编辑:
正如Holger Just所解释的那样:environment执行“环境”任务,如果你在轨道上,则加载环境。 这可能需要很长时间,但如果您的任务适用于数据库,il也可以帮助您。
In fact, when you're creating a rake task, :some_task is the name of the task you are calling.
For instance, in this case, you will call rake some_task
You also could define namespaces for your tasks :
namespace :my_tasks do desc "My first task" task :first_task => :environment do # DO SOMETHING end endAnd then you will call rake my_tasks:first_task in your console.
Hope it will help you,
Edit:
As explained by Holger Just, the :environment executes the "environment" task and if you are on rails, loads the environment. This could take a long time but il also helps you if your tasks works with the database.
更多推荐
发布评论