2017-06-22 27 views
1

在我的LWRP中擴展超市食譜,我得到了以下工作。在廚師中繼承Ruby時未初始化的常量錯誤

module PIWebsphereCookBook 
class WebsphereJbdc < WebsphereCookBook::WebsphereBase 

而當我介紹我自己的類中這2間,我越來越

require_relative './pi_websphere_base' 
module PIWebsphereCookBook 
    class WebsphereJbdc < PIWebsphereBase 

我試圖擴展基類,如下圖所示的「未初始化恆錯誤」:

module PIWebsphereCookBook 
    class PIWebsphereBase < WebsphereCookbook::WebsphereBase 

我從被引用類/文件被加載的日誌中看到

[2017-06-23T18:37:28-04:00] DEBUG: Loading cookbook pi_websphere's resources from /var/chef/cache/cookbooks/pi_websphere/resources/pi_websphere_base.rb 
[2017-06-23T18:37:28-04:00] DEBUG: Loaded contents of /var/chef/cache/cookbooks/pi_websphere/resources/pi_websphere_base.rb into resource pi_websphere_pi_websphere_base (Custom resource pi_websphere_pi_websphere_base from cookbook pi_websphere) 
[2017-06-23T18:37:28-04:00] DEBUG: Loading cookbook pi_websphere's resources from /var/chef/cache/cookbooks/pi_websphere/resources/websphere_j2c.rb 
[2017-06-23T18:37:28-04:00] DEBUG: Loaded contents of /var/chef/cache/cookbooks/pi_websphere/resources/websphere_j2c.rb into resource pi_websphere_websphere_j2c (Custom resource pi_websphere_websphere_j2c from cookbook pi_websphere) 
[2017-06-23T18:37:28-04:00] DEBUG: Loading cookbook pi_websphere's resources from /var/chef/cache/cookbooks/pi_websphere/resources/websphere_jdbc.rb 
[2017-06-23T18:37:28-04:00] DEBUG: Filtered backtrace of compile error: /var/chef/cache/cookbooks/pi_websphere/resources/websphere_jdbc.rb:3:in `<module:PIWebsphereCookBook>',/var/chef/cache/cookbooks/pi_websphere/resources/websphere_jdbc.rb:2:in `class_from_file' 
[2017-06-23T18:37:28-04:00] DEBUG: Backtrace entry for compile error: '/var/chef/cache/cookbooks/pi_websphere/resources/websphere_jdbc.rb:3:in `<module:PIWebsphereCookBook>'' 
[2017-06-23T18:37:28-04:00] DEBUG: Line number of compile error: '3' 

Recipe Compile Error in 
    /var/chef/cache/cookbooks/pi_websphere/resources/websphere_jdbc.rb 
NameError 
--------- 
uninitialized constant # 
<Class:0x000000052796d8>::PIWebsphereCookBook::PIWebsphereBase 

Cookbook Trace: 
--------------- 
    /var/chef/cache/cookbooks/pi_websphere/resources/websphere_jdbc.rb:3:in ` <module:PIWebsphereCookBook>' 
    /var/chef/cache/cookbooks/pi_websphere/resources/websphere_jdbc.rb:2:in ` class_from_file' 

    Relevant File Content: 
---------------------- 
/var/chef/cache/cookbooks/pi_websphere/resources/websphere_jdbc.rb: 
    1: require_relative './pi_websphere_base' 
    2: module PIWebsphereCookBook 
    3>> class WebsphereJbdc < PIWebsphereBase 
    4:  require_relative 'helper' 
    5: 

文件夾結構如下

[[email protected] pi_websphere]# tree 
. 
├── attributes 
│   └── default.rb 
├── Gemfile 
├── jaas_auth.py 
├── libraries 
│   ├── abc.rb 
│   ├── artifactory_helper.rb 
│    ├── pi_websphere_base.rb 
│   └── websphere_base.rb 
├── metadata.rb 
├── README.md 
├── resources 
│   ├── artifactory_client.rb 
│   ├── helper.rb 
│   ├── websphere_j2c.rb 
│   ├── websphere_jdbc.rb 

回答

1

給你需要確保含PIWebsphereBase第一次加載文件。通常食譜庫文件是以ASCII碼順序加載的,但是你可以用你在那裏的require_relative強制一些東西,但是被註釋掉了。你可能想要require_relative './pi_websphere_base'或類似的東西,或調整文件名。

+0

感謝您的關注。我也嘗試了你的建議,請找到更新的日誌和代碼。再次感謝 – patb23

+0

您切斷了實際的錯誤消息文本 – coderanger

+0

抱歉。添加完整的跟蹤 – patb23