Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rake Task and Namespaces [closed]

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?

like image 451
rails_newbie Avatar asked Feb 25 '26 19:02

rails_newbie


1 Answers

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
like image 67
Rajesh V Avatar answered Feb 28 '26 10:02

Rajesh V



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!