Method: Puppet::Provider.specificity

Defined in:
lib/puppet/provider.rb

.specificityInteger

Note:

Because of how this value is calculated there could be surprising side effects if a provider included an excessive amount of classes.

The number of requirements is based on the hash size of the matching defaultfor.

The ancestors is the Ruby Module::ancestors method and the number of classes returned is used to boost the score. The intent is that if two providers are equal, but one is more “derived” than the other (i.e. includes more classes), it should win because it is more specific).

Returns:

  • (Integer)

    Returns a numeric specificity for this provider based on how many requirements it has and number of ancestors. The higher the number the more specific the provider.



337
338
339
340
341
342
343
344
345
346
# File 'lib/puppet/provider.rb', line 337

def self.specificity
  # This strange piece of logic attempts to figure out how many parent providers there
  # are to increase the score. What is will actually do is count all classes that Ruby Module::ancestors
  # returns (which can be other classes than those the parent chain) - in a way, an odd measure of the
  # complexity of a provider).
  match = default_match
  length = match ? match.length : 0

  (length * 100) + ancestors.select { |a| a.is_a? Class }.length
end