- Mastering Puppet 5
- Ryan Russell Yates Jason Southgate
- 105字
- 2021-07-16 17:46:16
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