0

我正在使用 Ruby on Rails 和 Capistrano gem。我想干燥(不要重复自己)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

那么,我怎样才能干燥上面的代码,以免重复任务呢?

4

1 回答 1

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
于 2011-09-15T10:20:23.270 回答