I'm trying to better organize chef recipes by collecting common Ruby logic in a helper library. I saw examples declaring a class in a library (i.e. the Chef :: Recipe :: MyHelper Class) with several reusable methods inside. I also saw examples using the module in a similar way. In my case, I wanted to use the resource in several of these methods.
For example, let's say I want to provide a helper method that takes an array of service names and loops, stopping each of them using a service resource. I want to clean up the recipe files as much as possible and save some of this logic by simply calling the "stopServices (serviceList)" method.
If I define a helper library, for example:
class Chef::Recipe::MyHelper
def self.stopServices(serviceList)
serviceList.each do |svc|
service "#{svc}" do
action :stop
end
end
end
end
:
MyHelper.stopServices(serviceList)
: "undefined " " Chef:: Recipe:: MyHelper: Class".
? ( , MyHelper )? , ? , - , , , , , , .