Inheritance in the custom resources?


Hi all,

Am I getting this right - we no longer have inheritance in Custom Resources introduced in 12.5?

So what was the motivation and what is the best practice about this now? I clearly see a way I could inherit some resource from supermarket in my wrapper cookbook and get a lot of benefits from it. Why is it wrong / what shall I do instead (given that supermarket resource works great for me but I want some slight modifications, let’s say another way of calculating the default value for some attribute)?

Best regards,


The DSL-based resource syntax (previously called LWRPs, now custom resources) never supported actual inheritance. You can still totally use normal Ruby classes in libraries/ like before if that’s a feature you need, but that’s very very rare (usually making new providers for package or service). More common is a bunch of related resources needing shared functionality, which you can do with mixin modules.


Thanks @coderanger. That’s why I never liked LWRP either.

Anyway, @coderanger are you saying the resources should be designed in such a way they’d never have to be inherited? What if a resource I want to extend or modify is a Custom Resource and is defined in some open source cookbook from Supermarket?

I do not have any specific case right now, it’s more just a curiosity - trying get it right in my head. Looking for advice and some kind of a best practice on the subject.


It is very rare that community cookbook resources are designed for subclassing, yes. Specifically in my Poise family of cookbooks they are, but I’m a very special case. There just hasn’t been much of a reason for subclassing in most cases.