diff options
author | Luke Kanies <luke@madstop.com> | 2009-07-15 16:03:44 -0700 |
---|---|---|
committer | James Turnbull <james@lovedthanlost.net> | 2009-07-24 09:49:05 +1000 |
commit | 935c46351f6f6730569c50fd0c59e8157486b827 (patch) | |
tree | 80642f5693f3cd3ef7ae42e84b1ec79a037d603e /lib/puppet | |
parent | d95b687045920c7d7fed5da1fe03b0feac86327a (diff) | |
download | puppet-935c46351f6f6730569c50fd0c59e8157486b827.tar.gz puppet-935c46351f6f6730569c50fd0c59e8157486b827.tar.xz puppet-935c46351f6f6730569c50fd0c59e8157486b827.zip |
Fixing #2403 - provider specificity is richer and better
We have extended the concept of provider specificity so it
now includes both specified defaults and class depth, so:
* We are much more likely to choose the correct provider;
e.g., 'init' will be chosen over 'base'
* We're much less likely to print this warning, because it's
only printed when provider specificities are equal which
is much rarer
lib/puppet/provider.rb | 4 ++--
lib/puppet/type.rb | 4 ++--
spec/unit/type.rb | 17 +++++++++++++++++
test/ral/manager/type.rb | 22 ----------------------
4 files changed, 21 insertions(+), 26 deletions(-)
Signed-off-by: Luke Kanies <luke@madstop.com>
Diffstat (limited to 'lib/puppet')
-rw-r--r-- | lib/puppet/provider.rb | 4 | ||||
-rw-r--r-- | lib/puppet/type.rb | 4 |
2 files changed, 4 insertions, 4 deletions
diff --git a/lib/puppet/provider.rb b/lib/puppet/provider.rb index 1f13538af..3cef0dd71 100644 --- a/lib/puppet/provider.rb +++ b/lib/puppet/provider.rb @@ -91,8 +91,8 @@ class Puppet::Provider end end - def self.defaultnum - @defaults.length + def self.specificity + (@defaults.length * 100) + ancestors.select { |a| a.is_a? Class }.length end def self.initvars diff --git a/lib/puppet/type.rb b/lib/puppet/type.rb index 91f991814..098d83254 100644 --- a/lib/puppet/type.rb +++ b/lib/puppet/type.rb @@ -1465,8 +1465,8 @@ class Type # If we don't have any default we use suitable providers defaults = suitable if defaults.empty? - max = defaults.collect { |provider| provider.defaultnum }.max - defaults = defaults.find_all { |provider| provider.defaultnum == max } + max = defaults.collect { |provider| provider.specificity }.max + defaults = defaults.find_all { |provider| provider.specificity == max } retval = nil if defaults.length > 1 |