I am using Ruby on Rails and the Capistrano gem. I would like to DRY (Don’t Repeat Yourself) a Capistrano recipe.
In the deploy.rb file I have:
# First task
task :first_task do
...
run "cd #{current_path}; #{try_sudo} chmod -R 666 /log/production.log"
end
# Second task
task :second_task do
run "..."
# The following code is equal to that stated in the first task.
run "cd #{current_path}; #{try_sudo} chmod -R 666 /log/production.log"
end
So, how can I DRY the above code so to have not duplicated tasks?
Capistrano code is just ruby code with a Domain Specific Language (DSL), so you should be able to do: