How types and providers interact
The type definition declares the features that a provider
must have and what’s required to make them work. Providers can either be tested for whether they
suffice, or they can declare that they have the features. Because a type's properties call
getter and setter methods on the providers, the providers must define getters and setters for
each property (except ensure
).
Additionally, individual properties and parameters in the type can declare that they require one or more specific features, and Puppet throws an error if those parameters are used with providers missing those features:
newtype(:coloring) do feature :paint, "The ability to paint.", :methods => [:paint] feature :draw, "The ability to draw." newparam(:color, :required_features => %w{paint}) do ... end endThe first argument to the feature method is the name of the feature, the second argument is its description, and after that is a hash of options that help Puppet determine whether the feature is available. The only option currently supported is specifying one or more methods that must be defined on the provider. If no methods are specified, then the provider needs to specifically declare that it has that feature:
Puppet::Type.type(:coloring).provide(:drawer) do has_feature :draw endThe provider can specify multiple available features at the same time with
has_features
.
When you define features on your type, Puppet automatically defines the following class methods on the provider:
feature?
: Passed a feature name, returns true if the feature is available or false otherwise.features
: Returns a list of all supported features on the provider.satisfies?
: Passed a list of feature, returns true if they are all available, false otherwise.
Additionally, each feature gets a separate Boolean method, so the
above example would result in a paint?
method on the provider.