开发者

How to DRY Capistrano recipes?

I am using Ruby on Rails and the Capistrano gem. I would like to DRY (Don't Repeat Yourself) a Capistr开发者_运维百科ano 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:

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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜