:envi...">

Namespaces in Ruby Rake Tasks

Are the following equivalent?

namespace :resque do task setup: :environment do end end task "resque:setup" => :environment do end 
+4
source share
1 answer

In short: yes . When rake resque:setup starts, both of these tasks will be called.

Rake will combine these tasks. You can verify this by following these steps:

 p Rake.application.tasks 

That in this case will return something like

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

It is just an array containing 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 about how the internal elements of Rake work, check out Rake :: Task and Rake :: TaskManager

+3
source

All Articles