2017-10-22 12 views
0

내가 약간의 대부분은 문법과 관련된 문제 변경을요리사 (13) 구문은

node['java']['webapps'].each do |object| 
     name = object[0] 
     attributes = object[1] 
      if attributes.attribute?('enabled') 
       if attributes.enabled 
         if attributes.attribute?('x') 
           if attributes.x.attribute?('conf') 
             attributes.x.conf.each do |conf_file| 
               template "#{x_conf_dir}/#{conf_file}" do 
                source "#{conf_file}.erb" 
                mode '0755' 
                owner 'tomcat' 
                group 'tomcat' 
               end 
             end 
           end 
         end 
       end 
     end 
end 
"attributes.enabled 경우"에

요리사 클라이언트 오류가 바깥 쪽을 향하도록하고있어 13 버전 12에서 요리사 클라이언트를 업그레이드하려고 변경 버전 12 잘 작동 (이것은 계속해야하는 경우 활성화 된 배열 = TRUE)

는 지금은 타격있어

배열의 값을 확인하기위한 올바른 구문은 무엇인가 "정의되지 않은 방법은 '사용 가능'"?

답변

1

지금은 attributes['enabled']이어야하지만 그 코드는 어쨌든 엄청나게 정리할 수 있습니다. 당신이 많은 대각선 들여 쓰기, 아마 당신의 코드를 다시 생각해 볼

node['java']['webapps'].each do |name, app_attrs| 
    conf_file = app_attrs.read('enabled', 'x', 'conf') 
    if conf_file 
    template .. same stuff here 
    end 
end 

때마다 :)

을 :이 Hash#dig 같이있는 node.read 방법을 사용하여, 같은 일을 생각한다