puppetlabs/puppet — pull request #1443 by wfarr (2013-02-01 09:30:33+00:00)
Title: (#19001) Allow autorequire to work with classes

Under the current implementation, though classes are to be considered first-class resources, you cannot use `Puppet::Type.autorequire` with class resources.

The reason for this is the old implementation checked to see "is this a valid type". The method of checking this doesn't support 'class' as a valid resource type though, as evidenced by the following:

``` ruby
require "puppet" #=> true
Puppet::Type.type(:file) #=> Puppet::Type::File
Puppet::Type.type(:class) #=> nil
```

This change set introduces a simple check to see if the type we're dealing with is a class before doing the current type checking.

This change has been confirmed with the use a custom Puppet type `Repository` that includes the following:

``` ruby
autorequire :class do
if provider.respond_to? :autorequire
provider.autorequire.each do |requirement|
Puppet.warning("got an autorequire of: #{requirement}")
end
else
[]
end
end
```

With the patch above applied to Puppet 3.0.2, it results in the following output appearing before every `Repository` resource in the run output:

```
Warning: got an autorequire of: git
```

I've tested all releases of Puppet 3.0.x, and none exhibit the expected behavior without this change.

Related RedMine ticket: https://projects.puppetlabs.com/issues/19001