patb23
patb23

Reputation: 397

Chef LWRP referencing relative resource

I am trying to create a LWRP to extend a supermarket cookbook 'webpshere'.

In my resource file, I am trying to extend this class with a base class found in parent cook book.

In the code below, 'WebsphereBase' is defined in the parent library 'websphere_base'. Can I get help on how to reference it? Thanks

    #require 'websphere_base'
    module PIWebsphereCookBook
    class WebsphereJbdc < WebsphereBase
    require_relative 'helper'

Upvotes: 1

Views: 134

Answers (2)

coderanger
coderanger

Reputation: 54267

You don't need to require things coming from upstream cookbooks, nor can you (except for my weirdo cookbooks). All libs for cookbooks you depend on will be loaded by the time your library files run.

Upvotes: 1

Holger Just
Holger Just

Reputation: 55908

In the source of the cookbook, you can see that the WebsphereBase class is defined inside the WebsphereCookbook module.

To reference this class from outside this module, you have to name the nesting so that Ruby is able to find the class you are referring to. With youur example, this can look similar to:

module PIWebsphereCookBook
  class WebsphereJbdc < WebsphereCookbook::WebsphereBase
    require_relative 'helper'
    # ...
  end
end

Upvotes: 1

Related Questions