Skip to content

Instantly share code, notes, and snippets.

@jkeiser
Last active December 30, 2015 22:19
Show Gist options
  • Save jkeiser/7893487 to your computer and use it in GitHub Desktop.
Save jkeiser/7893487 to your computer and use it in GitHub Desktop.
Proposal: move Chef resources out of Chef::Resource

Provider location proposal (File.exists?)

This proposal attempts to solve two problems:

  • The fact that it is hard to create Resources and Providers outside the Chef:: namespace
  • The fact that classes in the Chef::Resource and Chef::Provider namespace (like File) make it harder to write providers (calling File.exists? fails because it grabs Chef::Provider::File instead of ::File)

Easy Outside Provider Declarations

All resources will need to declare what they provide with the "register_resource" declaration, which will be extended with the ability to specify the Provider class.

class Blah::Resource::ArmAndHammer < Chef::Resource
  register_resource 'baking_soda', Blah::Provider::ArmAndHammer
end

If the resource name is not specified, it will be inferred from the class name:

class Blah::Resource::ArmAndHammer < Chef::Resource
  register_resource Blah::Provider::ArmAndHammer
end

If the Provider class is not specified, it will look to see if the Resource class is under a directory named "Resource", and look for a Provider class with the same name in the corresponding Provider class (in this case, Blah::Resource::MyResource will have a default provider Blah::Provider::MyResource).

class Blah::Resource::ArmAndHammer < Chef::Resource
  register_resource 'arm_and_hammer'
end

If the class is in a subclass of Chef::Resource and exists in <any namespace>::Resource, it will automatically get a standard_resource declaration with no parameters, so there is no decoration needed.

If two resources provide the same thing on the same platform, the winner is undefined.

Move LWRPs Out of Chef::

LWRPs are presently housed in Chef::Resource and Chef::Provider. We will add them into the "ChefLWRP" module (see this line and add a "provides" directive to point them at the right place.

Move Standard Resources Out of Chef::Resource

Once the former is done, all Chef standard resources and providers will move from Chef::Provider and Chef::Resource to Chef::Core::Provider and Chef::Core::Resource.

@jkeiser
Copy link
Author

jkeiser commented Dec 10, 2013

I'm actually pretty cool with Dan's proposal, actually. If you declare a subclass of Chef::Resource inside ::Resource, it will automatically get a provides. That would preserve backcompat and make it maximally easy to move classes over!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment