Hi @rayterrill
When first learning Chef I used the DSL relatively successfully but did not really know what I was doing or how best to write a cookbook. What I would say is do not underestimate the role of Ruby in the Chef DSL; as I said you don’t need to know Ruby to write a cookbook but it will help you write better cookbooks and you’ll know what to do when things go wrong.
Here are a few possible ways to get to know the Classes and methods
- Branch or download the Chef source code
- Debug your code with Chef Zero and Pry
- Debug your code with Chef-Zero and Chef-Shell
The chef source code is here https://github.com/chef/chef
Debugging with Chef-Zero and Pry can be a bit involved, I wrote some notes here https://github.com/chrisgit/chef-debugging
A quick win will be to load up Chef-Shell (ideally with your recipes and handler loaded) but you can just run Chef-Shell without loading any cookbooks.
Chef-Shell is an interactive environment used to help debug Chef cookbooks, I love it, especially when tracking down where the value of an attribute comes from.
With Chef installed at a command prompt type “chef-shell”. Chef-Shell has various “modes” such as attribute mode and recipe mode, for interrogating classes though you just need to be in the default mode after Chef-Shell has loaded, here are a few helpful commands.
Get methods of an instance of the Chef::Node class
node.methods
Get methods from a class definition
Chef::Node.methods
Chef::Node.instance_methods
If the method list is to big then restrict with grep
Chef::Node.methods.grep(/method/)
Chef::RunStatus.methods
Get all of the classes loaded
class_list = []
ObjectSpace.each_object { |o| class_list << o.name if o.class == Class }
class_list
Therefore if you want to look at the methods that contain the word “time” you can interrogate the instance of Chef::RunStatus or the class definition in your handler (using puts or Chef::Log.info if you can’t get a break point to work), below looks at the class definition for RunStatus and gets the instance methods with the word time in them.
Chef::RunStatus.instance_methods.grep(/time/)
Ruby has a rich metadata system which can be interrogated so once you are in Ruby prompt you can start to interrogate the classes!
So if you don’t want to use Chef-Shell then you can run interactive Ruby (IRB), go to a command prompt on a machine with Ruby installed and in the path, type “irb”, when interactive Ruby loads at the prompt load the chef libraries by typing require ‘chef’. After typing that the significant Chef libraries will be loaded and you can start to reflect on the class definitions.
Hope this answers your question and helps with your handler.