class PluginBinding
To provide a space to instance variables that will be used by any Ohai plugins that use ERB templating to insert content.
Public Class Methods
Create a new object that will define instance variables out of the hash's key-value pairs. This will create a safe place to define instance variables within a binding that can used when rendering the content of the ERB.
# File lib/chefspec/ohai.rb, line 70 def initialize(template_variables) Hash(template_variables).each do |key,value| instance_variable_set("@#{key}",value) end end
Public Instance Methods
This exposes the private binding method to allow it to be used as the specified binding when parsing ERB template.
# File lib/chefspec/ohai.rb, line 94 def expose_binding! binding end
Within a template you can use `node`. This method provides support for that by creating this method that maps to the @node instance variable. This means that if you want to define a Ohai plugin that uses the node object and test it, then you are required to provide the values to make that work for the test.
NOTE: A consideration here would be to use Fauxhai instead of requiring a
user to provide each attribute. This would get time consumsing to create tests if the Ohai plugin used a lot of node attributes.
# File lib/chefspec/ohai.rb, line 85 def node if @node.nil? raise NoNodeDataProvidedToTemplatePlugin end @node end