我正在使用Ruby on Rails和Capistrano宝石。我想干(不要重复自己)Capistrano食谱。
在我的deploy.rb
文件中:
# 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
那么,如何干掉上面的代码,以便没有重复的任务呢?
答案 0 :(得分:4)
Capistrano代码只是具有域特定语言(DSL)的ruby代码,因此您应该能够:
def chmod_log
run "cd #{current_path}; #{try_sudo} chmod -R 666 /log/production.log"
end
# First task
task :first_task do
...
chmod_log
end
# Second task
task :second_task do
run "..."
# The following code is equal to that stated in the first task.
chmod_log
end