2

Is it a good idea to put rake tasks with different namespaces in different folders under task, also if there's only one file with a different namespace what should be done?

rails_newbie
  • 108
  • 1
  • 12

1 Answers1

6

Generally we don't need a separate folder for each namespace, prefer having one rake file for one namespace.

eg:

lib/rake/clear_log.rake

let's say I have the rake task to clean up the logs called log_clear

Here’s what I put in lib/tasks/log_clear.rake:

namespace :log_clear  do
  desc "clear logs for development"
  task :development => :environment do
        ...
  end
  desc "clear logs for staging"
  task :staging => :environment do
        ...
  end
  desc "clear logs for production"
  task :production => :environment do
        ...
  end

    desc "clear all logs"
  task :all => [:development, :staging, :production]
end

rake log_clear # clears all logs
rake log_clear:all # clears all logs
rake log_clear:development # clears development logs
rake log_clear:staging # clears staging logs 
rake log_clear:production # clears production logs
Rajesh V
  • 146
  • 4