廚師是用Ruby編寫的,能夠廣泛使用Ruby來設計自定義DSL。幾乎每個廚師配置文件都是使用基於Ruby的DSL編寫的。
這意味着,爲了有效地使用廚師,你應該熟悉的Ruby語法包括
- 基本的語法
- 數據類型(主要區別與其他語言的符號)
- 塊
在Ruby中,您不需要了解很多關於元編程的知識。
您發佈的代碼的情況是基於Ruby的DSL的一個很好的例子。讓我稍微解釋一下。
# Call the method directory passing the path and a block
# containing some code to be evaluated
directory "/home/test/mydir" do
# chown the directory to the test user
owner "test"
# set the permissions to 0555
mode "0755"
# create the directory if it does not exists
action :create
# equivalent of -p flag in the mkdir
recursive true
end
塊是指定一組操作(在這種情況下創建,設置權限,等等)在單一上下文進行評估(在這種情況下,該路徑的上下文中)的簡便方法。
你在閱讀什麼文件? –
主要是互聯網:目前http://gettingstartedwithchef.com/first-steps-with-chef.html – mirk
我也在學習,從而證實我問。 :) –