2011-09-15 31 views
0

我正在使用Ruby on Rails和Capistrano創業板。我想幹(不要重複自己)一個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 

那麼,如何我乾的上述代碼,以便有沒有重複的任務?

回答

4

Capistrano的代碼僅僅是Ruby代碼與領域特定語言(DSL),所以你應該能夠做到:

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