3
namespace :jobs do
  task :environment => [:environment] do
    #Something cool
  end
end

This causes a circular dependency on :environment, which I am just trying to depend on the Rails task environment.

How can this be correctly setup?

nkm
  • 5,844
  • 2
  • 24
  • 38
Carson Reinke
  • 713
  • 5
  • 16
  • What are you trying to do? Are you trying to append some code to the built in :environment task? Or did you just really want to name your custom task :environment? If the latter, then just name it something else. – MrDanA Feb 21 '12 at 17:11
  • I really want to name my task :environment and renaming it does not answer the question. – Carson Reinke Feb 21 '12 at 17:17

2 Answers2

10

You should also be able to say:

task :environment => [ 'rake:environment' ] do ... end

The 'rake:' namespace is the top level namespace. It's like doing ::CONSTANT_NAME in ruby.

Jim Weirich
  • 261
  • 1
  • 3
5

I have just had exactly the same issue, where a task in a namespace is trying to call a task of the same name in the parent namespace. This is indeed possible.

namespace :jobs do
  task :environment => [ '^environment' ] do
    #Something cool
  end
end

Each caret you use will begin name resolution one level higher in the namespace hierarchy. See: http://rake.rubyforge.org/files/doc/rakefile_rdoc.html

beefsack
  • 428
  • 1
  • 5
  • 10