Spencer Williams
Spencer Williams

Reputation: 922

How to access namespace from within a rake task?

My rake task (rake v 0.9.2.2) includes a bit to print out the name of the task. I'd like it to also print its namespace. Kind of like the following:

namespace :yelp do
    desc "..."
    task :scrape => :environment do
        puts "rake #{task.namespace}:#{task.name}"
    end
end

The problem is that namespace is a private method.

rake aborted!
private method `namespace' called for <Rake::Task  => []>:Rake::Task

Anyone have a solution?

Upvotes: 2

Views: 769

Answers (1)

Spencer Williams
Spencer Williams

Reputation: 922

task.name includes the namespace. Use this tip to get task.name to print under rake 0.9.2.2.

Upvotes: 2

Related Questions