summaryrefslogtreecommitdiff
path: root/lib/chef/resource.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/chef/resource.rb')
-rw-r--r--lib/chef/resource.rb20
1 files changed, 20 insertions, 0 deletions
diff --git a/lib/chef/resource.rb b/lib/chef/resource.rb
index fdfa9766ab..85b1b02106 100644
--- a/lib/chef/resource.rb
+++ b/lib/chef/resource.rb
@@ -899,11 +899,31 @@ class Chef
@resource_name = value.to_sym
provides self.resource_name
end
+ # Backcompat: set resource name for classes in Chef::Resource automatically
+ if !@resource_name && self.name
+ chef, resource, class_name, *extra = self.name.split('::')
+ if chef == 'Chef' && resource == 'Resource' && extra.size == 0
+ @resource_name = convert_to_snake_case(self.name.split('::')[-1])
+ end
+ end
@resource_name
end
alias :resource_name= :resource_name
#
+ # Use the class name as the resource name.
+ #
+ # Munges the last part of the class name from camel case to snake case,
+ # and sets the resource_name to that:
+ #
+ # A::B::BlahDBlah -> blah_d_blah
+ #
+ def use_automatic_resource_name
+ automatic_name = convert_to_snake_case(self.name.split('::')[-1])
+ resource_name automatic_name
+ end
+
+ #
# The module where Chef should look for providers for this resource.
# The provider for `MyResource` will be looked up using
# `provider_base::MyResource`. Defaults to `Chef::Provider`.