class Puppet::Util::ProviderFeatures::ProviderFeature

This class models provider features and handles checking whether the features are present. @todo Unclear what is api and what is private in this class

Attributes

docs[RW]
methods[RW]
name[RW]

Public Class Methods

new(name, docs, methods: nil) click to toggle source
   # File lib/puppet/util/provider_features.rb
34 def initialize(name, docs, methods: nil)
35   self.name = name.intern
36   self.docs = docs
37   @methods = methods
38 end

Public Instance Methods

available?(obj) click to toggle source

Are all of the requirements met? Requirements are checked by checking if feature predicate methods have been generated - see {#methods_available?}. @param obj [Object, Class] the object or class to check if requirements are met @return [Boolean] whether all requirements for this feature are met or not.

   # File lib/puppet/util/provider_features.rb
23 def available?(obj)
24   if self.methods
25     return !!methods_available?(obj)
26   else
27     # In this case, the provider has to declare support for this
28     # feature, and that's been checked before we ever get to the
29     # method checks.
30     return false
31   end
32 end

Private Instance Methods

methods_available?(obj) click to toggle source

Checks whether all feature predicate methods are available. @param obj [Object, Class] the object or class to check if feature predicates are available or not. @return [Boolean] Returns whether all of the required methods are available or not in the given object.

   # File lib/puppet/util/provider_features.rb
45 def methods_available?(obj)
46   methods.each do |m|
47     if obj.is_a?(Class)
48       return false unless obj.public_method_defined?(m)
49     else
50       return false unless obj.respond_to?(m)
51     end
52   end
53   true
54 end