Module Chef::Mixin::ParamsValidate
In: lib/chef/mixin/params_validate.rb

Methods

Public Instance methods

Takes a hash of options, along with a map to validate them. Returns the original options hash, plus any changes that might have been made (through things like setting default values in the validation map)

For example:

  validate({ :one => "neat" }, { :one => { :kind_of => String }})

Would raise an exception if the value of :one above is not a kind_of? string. Valid map options are:

:default:Sets the default value for this parameter.
:callbacks:Takes a hash of Procs, which should return true if the argument is valid. The key will be inserted into the error message if the Proc does not return true:
   "Option #{key}'s value #{value} #{message}!"
:kind_of:Ensure that the value is a kind_of?(Whatever). If passed an array, it will ensure that the value is one of those types.
:respond_to:Ensure that the value has a given method. Takes one method name or an array of method names.
:required:Raise an exception if this parameter is missing. Valid values are true or false, by default, options are not required.
:regex:Match the value of the paramater against a regular expression.
:equal_to:Match the value of the paramater with ==. An array means it can be equal to any of the values.

[Validate]