开发者

Namespaces in Ruby Rake Tasks

开发者 https://www.devze.com 2023-03-16 15:29 出处:网络
Are the following equivalent? namespace :resque do task setup: :environ开发者_Go百科ment do end end task \"resque:setup\" => :environment do

Are the following equivalent?

namespace :resque do
  task setup: :environ开发者_Go百科ment do
  end
end

task "resque:setup" => :environment do
end


In short: yes. When running rake resque:setup both of these tasks will be invoked.

Rake will merge these tasks. You can test this by doing the following:

p Rake.application.tasks

Which in this case would return something like

[<Rake::Task resque:setup => [environment]>]

Which is simply an Array holding a single Rake::Task object. You can also check the scope or list of namespaces for a task by doing:

p Rake.application.tasks.first.scope
  #=> ["resque"]

If you want to learn a little more on how the internals of Rake work, check out Rake::Task and Rake::TaskManager

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号