如何干卡皮斯特拉诺食谱?

时间:2011-09-15 10:16:57

标签: ruby-on-rails ruby ruby-on-rails-3 capistrano recipe

我正在使用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

那么,如何干掉上面的代码,以便没有重复的任务呢?

1 个答案:

答案 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