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
33 def initialize(name, docs, methods: nil)
34   self.name = name.intern
35   self.docs = docs
36   @methods = methods
37 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
22 def available?(obj)
23   if self.methods
24     return !!methods_available?(obj)
25   else
26     # In this case, the provider has to declare support for this
27     # feature, and that's been checked before we ever get to the
28     # method checks.
29     return false
30   end
31 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
44 def methods_available?(obj)
45   methods.each do |m|
46     if obj.is_a?(Class)
47       return false unless obj.public_method_defined?(m)
48     else
49       return false unless obj.respond_to?(m)
50     end
51   end
52   true
53 end