2013-12-19 19 views
1

我對Ruby有點新,但是我已經閱讀了很多關於塊的教程和文檔。然而,我真的不明白下面的語法,這是在一個廚師食譜中使用:廚師中使用的Ruby塊,理解語法的問題

template "/etc/profile.d/golang.sh" do 
    source "golang.sh.erb" 
    owner "root" 
    group "root" 
    mode 0755 
end 

我該如何解析呢?什麼是template?它是一個函數,通過2個參數("/etc/profile.d/golang.sh"和塊)? sourceowner等功能也是如此嗎?

對不起,如果這是一個基本的問題!

+0

我已經在這裏更全面地回答了這個問題:http://stackoverflow.com/questions/19719968/ruby-code-blocks-and-chef/19726723#19726723 – cassianoleal

回答

2

我回答相同的問題在https://stackoverflow.com/a/20569738/123527

# Call the method directory passing the path and a block 
# containing some code to be evaluated in the given context 
template "/etc/profile.d/golang.sh" do 

    # Use the ERB template defined at "golang.sh.erb" 
    source "golang.sh.erb" 

    # chown the file to the user root 
    owner "root" 
    group "root" 

    # set the permissions to 0555 
    mode "0755" 
end 

塊是指定一組操作的一種方便的方式(在這種情況下創建,設置權限,等等)在單一上下文進行評估(在此在該路徑的情況下)。

templatesourceowner,group等都是Ruby方法。