Checking datatype compatibility with munge

To decide whether an underlying provider property should be updated, a simple equality comparison is made between the provided value and the value retrieved using the provider.

The munge method can ensure that the data supplied by the user has a consistent datatype with that expected to be returned from the provider. For example, we could call the munge method to make sure that the user-supplied datatype of integer or numeric string is compatible with the integer required by the provider, as shown in the following code:

Puppet::Type.newtype(:mynewtype) do   ...   newparam(:identifier) do     munge do |value|       Integer(value)     end   end   ... end

Get Mastering Puppet 5 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.