summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Keiser <john@johnkeiser.com>2015-05-28 11:32:10 -0700
committerJohn Keiser <john@johnkeiser.com>2015-06-01 08:02:05 -0700
commit46e3f2258b1b04ca6030b5ef1575adadaa920e08 (patch)
treef59066b287aee399b923de9346be4a42f4e20924
parent5998cc7315507e649bb76f139c07715f6e590707 (diff)
downloadchef-46e3f2258b1b04ca6030b5ef1575adadaa920e08.tar.gz
Add use_automatic_resource_name
-rw-r--r--DOC_CHANGES.md8
-rw-r--r--lib/chef/resource.rb20
-rw-r--r--lib/chef/resource/apt_package.rb2
-rw-r--r--lib/chef/resource/bash.rb2
-rw-r--r--lib/chef/resource/batch.rb2
-rw-r--r--lib/chef/resource/bff_package.rb2
-rw-r--r--lib/chef/resource/breakpoint.rb2
-rw-r--r--lib/chef/resource/chef_gem.rb2
-rw-r--r--lib/chef/resource/cookbook_file.rb2
-rw-r--r--lib/chef/resource/cron.rb2
-rw-r--r--lib/chef/resource/csh.rb2
-rw-r--r--lib/chef/resource/deploy.rb2
-rw-r--r--lib/chef/resource/deploy_revision.rb4
-rw-r--r--lib/chef/resource/directory.rb2
-rw-r--r--lib/chef/resource/dpkg_package.rb2
-rw-r--r--lib/chef/resource/dsc_resource.rb2
-rw-r--r--lib/chef/resource/dsc_script.rb2
-rw-r--r--lib/chef/resource/easy_install_package.rb2
-rw-r--r--lib/chef/resource/env.rb2
-rw-r--r--lib/chef/resource/erl_call.rb2
-rw-r--r--lib/chef/resource/execute.rb2
-rw-r--r--lib/chef/resource/file.rb2
-rw-r--r--lib/chef/resource/freebsd_package.rb2
-rw-r--r--lib/chef/resource/gem_package.rb2
-rw-r--r--lib/chef/resource/git.rb2
-rw-r--r--lib/chef/resource/group.rb2
-rw-r--r--lib/chef/resource/homebrew_package.rb2
-rw-r--r--lib/chef/resource/http_request.rb2
-rw-r--r--lib/chef/resource/ifconfig.rb2
-rw-r--r--lib/chef/resource/ips_package.rb2
-rw-r--r--lib/chef/resource/link.rb2
-rw-r--r--lib/chef/resource/log.rb2
-rw-r--r--lib/chef/resource/lwrp_base.rb2
-rw-r--r--lib/chef/resource/macosx_service.rb2
-rw-r--r--lib/chef/resource/macports_package.rb2
-rw-r--r--lib/chef/resource/mdadm.rb2
-rw-r--r--lib/chef/resource/mount.rb2
-rw-r--r--lib/chef/resource/ohai.rb2
-rw-r--r--lib/chef/resource/openbsd_package.rb2
-rw-r--r--lib/chef/resource/package.rb2
-rw-r--r--lib/chef/resource/pacman_package.rb2
-rw-r--r--lib/chef/resource/paludis_package.rb2
-rw-r--r--lib/chef/resource/perl.rb2
-rw-r--r--lib/chef/resource/portage_package.rb2
-rw-r--r--lib/chef/resource/powershell_script.rb2
-rw-r--r--lib/chef/resource/python.rb2
-rw-r--r--lib/chef/resource/reboot.rb2
-rw-r--r--lib/chef/resource/registry_key.rb2
-rw-r--r--lib/chef/resource/remote_directory.rb2
-rw-r--r--lib/chef/resource/remote_file.rb2
-rw-r--r--lib/chef/resource/route.rb2
-rw-r--r--lib/chef/resource/rpm_package.rb2
-rw-r--r--lib/chef/resource/ruby.rb2
-rw-r--r--lib/chef/resource/ruby_block.rb2
-rw-r--r--lib/chef/resource/scm.rb2
-rw-r--r--lib/chef/resource/script.rb2
-rw-r--r--lib/chef/resource/service.rb2
-rw-r--r--lib/chef/resource/smartos_package.rb2
-rw-r--r--lib/chef/resource/solaris_package.rb2
-rw-r--r--lib/chef/resource/subversion.rb2
-rw-r--r--lib/chef/resource/template.rb2
-rw-r--r--lib/chef/resource/timestamped_deploy.rb2
-rw-r--r--lib/chef/resource/user.rb2
-rw-r--r--lib/chef/resource/whyrun_safe_ruby_block.rb2
-rw-r--r--lib/chef/resource/windows_package.rb2
-rw-r--r--lib/chef/resource/windows_service.rb2
-rw-r--r--lib/chef/resource/yum_package.rb2
-rw-r--r--spec/integration/recipes/recipe_dsl_spec.rb2
-rw-r--r--spec/integration/recipes/resource_definition_spec.rb9
-rw-r--r--spec/support/lib/chef/resource/cat.rb2
-rw-r--r--spec/support/lib/chef/resource/one_two_three_four.rb2
-rw-r--r--spec/support/lib/chef/resource/with_state.rb2
-rw-r--r--spec/support/lib/chef/resource/zen_follower.rb2
-rw-r--r--spec/support/lib/chef/resource/zen_master.rb2
-rw-r--r--spec/unit/recipe_spec.rb4
-rw-r--r--spec/unit/resource_spec.rb14
76 files changed, 119 insertions, 80 deletions
diff --git a/DOC_CHANGES.md b/DOC_CHANGES.md
index 629ff147c2..b5eb124f26 100644
--- a/DOC_CHANGES.md
+++ b/DOC_CHANGES.md
@@ -14,12 +14,16 @@ automatically. Instead, `resource_name` is required in order to have DSL:
```ruby
module MyModule
class MyResource < Chef::Resource
- resource_name :my_resource
- provides :some_other_name, os: 'linux' # A second resource DSL, only on linux
+ use_automatic_resource_name # Names the resource "my_resource"
end
end
```
+`resource_name :my_resource` may be used to explicitly set the resource name.
+
+`provides :my_resource`, still works, but at least one resource_name *must* be
+set for the resource to work.
+
Authors of HWRPs need to be aware that in the future all resources and providers will be required to include a provides line. Starting with Chef 12.4.0 any HWRPs in the `Chef::Resource` or `Chef::Provider` namespaces that do not have provides lines will trigger deprecation warning messages when called. The LWRPBase code does `provides` automatically so LWRP authors and users who write classes that inherit from LWRPBase do not need to explicitly include provides lines.
Users are encouraged to declare resources in their own namespaces instead of putting them in the special `Chef::Resource` namespace.
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`.
diff --git a/lib/chef/resource/apt_package.rb b/lib/chef/resource/apt_package.rb
index eb61972b74..83bb6906d4 100644
--- a/lib/chef/resource/apt_package.rb
+++ b/lib/chef/resource/apt_package.rb
@@ -23,7 +23,7 @@ class Chef
class Resource
class AptPackage < Chef::Resource::Package
- resource_name :apt_package
+ use_automatic_resource_name
provides :package, os: "linux", platform_family: [ "debian" ]
def initialize(name, run_context=nil)
diff --git a/lib/chef/resource/bash.rb b/lib/chef/resource/bash.rb
index 2e21d3db69..554d2de924 100644
--- a/lib/chef/resource/bash.rb
+++ b/lib/chef/resource/bash.rb
@@ -22,7 +22,7 @@ require 'chef/provider/script'
class Chef
class Resource
class Bash < Chef::Resource::Script
- resource_name :bash
+ use_automatic_resource_name
def initialize(name, run_context=nil)
super
diff --git a/lib/chef/resource/batch.rb b/lib/chef/resource/batch.rb
index d79127e2f3..8a19e04174 100644
--- a/lib/chef/resource/batch.rb
+++ b/lib/chef/resource/batch.rb
@@ -22,7 +22,7 @@ class Chef
class Resource
class Batch < Chef::Resource::WindowsScript
- resource_name :batch
+ use_automatic_resource_name
provides :batch, os: "windows"
def initialize(name, run_context=nil)
diff --git a/lib/chef/resource/bff_package.rb b/lib/chef/resource/bff_package.rb
index cd60b94cdd..f31fe6a0d8 100644
--- a/lib/chef/resource/bff_package.rb
+++ b/lib/chef/resource/bff_package.rb
@@ -22,7 +22,7 @@ require 'chef/provider/package/aix'
class Chef
class Resource
class BffPackage < Chef::Resource::Package
- resource_name :bff_package
+ use_automatic_resource_name
end
end
end
diff --git a/lib/chef/resource/breakpoint.rb b/lib/chef/resource/breakpoint.rb
index 3f09d1d442..dca4fd04a6 100644
--- a/lib/chef/resource/breakpoint.rb
+++ b/lib/chef/resource/breakpoint.rb
@@ -22,7 +22,7 @@ require 'chef/resource'
class Chef
class Resource
class Breakpoint < Chef::Resource
- resource_name :breakpoint
+ use_automatic_resource_name
def initialize(action="break", *args)
super(caller.first, *args)
diff --git a/lib/chef/resource/chef_gem.rb b/lib/chef/resource/chef_gem.rb
index b3c96fcbec..e4e3ccfbab 100644
--- a/lib/chef/resource/chef_gem.rb
+++ b/lib/chef/resource/chef_gem.rb
@@ -23,7 +23,7 @@ class Chef
class Resource
class ChefGem < Chef::Resource::Package::GemPackage
- resource_name :chef_gem
+ use_automatic_resource_name
def initialize(name, run_context=nil)
super
diff --git a/lib/chef/resource/cookbook_file.rb b/lib/chef/resource/cookbook_file.rb
index b12735a56c..ade9c0e3e3 100644
--- a/lib/chef/resource/cookbook_file.rb
+++ b/lib/chef/resource/cookbook_file.rb
@@ -27,7 +27,7 @@ class Chef
class CookbookFile < Chef::Resource::File
include Chef::Mixin::Securable
- resource_name :cookbook_file
+ use_automatic_resource_name
def initialize(name, run_context=nil)
super
diff --git a/lib/chef/resource/cron.rb b/lib/chef/resource/cron.rb
index 70d4a26d53..daf462866e 100644
--- a/lib/chef/resource/cron.rb
+++ b/lib/chef/resource/cron.rb
@@ -27,7 +27,7 @@ class Chef
state_attrs :minute, :hour, :day, :month, :weekday, :user
- resource_name :cron
+ use_automatic_resource_name
def initialize(name, run_context=nil)
super
diff --git a/lib/chef/resource/csh.rb b/lib/chef/resource/csh.rb
index 7eae72d968..1c89f2aca6 100644
--- a/lib/chef/resource/csh.rb
+++ b/lib/chef/resource/csh.rb
@@ -22,7 +22,7 @@ require 'chef/provider/script'
class Chef
class Resource
class Csh < Chef::Resource::Script
- resource_name :csh
+ use_automatic_resource_name
def initialize(name, run_context=nil)
super
diff --git a/lib/chef/resource/deploy.rb b/lib/chef/resource/deploy.rb
index bfa3679c97..014e690e65 100644
--- a/lib/chef/resource/deploy.rb
+++ b/lib/chef/resource/deploy.rb
@@ -50,7 +50,7 @@ class Chef
# release directory. Callback files can contain chef code (resources, etc.)
#
class Deploy < Chef::Resource
- resource_name :deploy
+ use_automatic_resource_name
provider_base Chef::Provider::Deploy
diff --git a/lib/chef/resource/deploy_revision.rb b/lib/chef/resource/deploy_revision.rb
index ecb428018b..86a8631ba7 100644
--- a/lib/chef/resource/deploy_revision.rb
+++ b/lib/chef/resource/deploy_revision.rb
@@ -23,13 +23,13 @@ class Chef
# deployment strategy (provider)
class DeployRevision < Chef::Resource::Deploy
- resource_name :deploy_revision
+ use_automatic_resource_name
end
class DeployBranch < Chef::Resource::DeployRevision
- resource_name :deploy_branch
+ use_automatic_resource_name
end
diff --git a/lib/chef/resource/directory.rb b/lib/chef/resource/directory.rb
index d49e331639..ea1805353d 100644
--- a/lib/chef/resource/directory.rb
+++ b/lib/chef/resource/directory.rb
@@ -32,7 +32,7 @@ class Chef
include Chef::Mixin::Securable
- resource_name :directory
+ use_automatic_resource_name
def initialize(name, run_context=nil)
super
diff --git a/lib/chef/resource/dpkg_package.rb b/lib/chef/resource/dpkg_package.rb
index 38210bcf41..e0b86947f1 100644
--- a/lib/chef/resource/dpkg_package.rb
+++ b/lib/chef/resource/dpkg_package.rb
@@ -23,7 +23,7 @@ class Chef
class Resource
class DpkgPackage < Chef::Resource::Package
- resource_name :dpkg_package
+ use_automatic_resource_name
provides :dpkg_package, os: "linux"
end
diff --git a/lib/chef/resource/dsc_resource.rb b/lib/chef/resource/dsc_resource.rb
index d86368b96e..cdfdff54f0 100644
--- a/lib/chef/resource/dsc_resource.rb
+++ b/lib/chef/resource/dsc_resource.rb
@@ -21,7 +21,7 @@ class Chef
class Resource
class DscResource < Chef::Resource
- resource_name :dsc_resource
+ use_automatic_resource_name
provides :dsc_resource, os: "windows"
include Chef::DSL::Powershell
diff --git a/lib/chef/resource/dsc_script.rb b/lib/chef/resource/dsc_script.rb
index f1aeb22885..4eabb92438 100644
--- a/lib/chef/resource/dsc_script.rb
+++ b/lib/chef/resource/dsc_script.rb
@@ -22,7 +22,7 @@ class Chef
class Resource
class DscScript < Chef::Resource
- resource_name :dsc_script
+ use_automatic_resource_name
provides :dsc_script, platform: "windows"
def initialize(name, run_context=nil)
diff --git a/lib/chef/resource/easy_install_package.rb b/lib/chef/resource/easy_install_package.rb
index e6c9cd180d..2483b0a8b7 100644
--- a/lib/chef/resource/easy_install_package.rb
+++ b/lib/chef/resource/easy_install_package.rb
@@ -22,7 +22,7 @@ class Chef
class Resource
class EasyInstallPackage < Chef::Resource::Package
- resource_name :easy_install_package
+ use_automatic_resource_name
def easy_install_binary(arg=nil)
set_or_return(
diff --git a/lib/chef/resource/env.rb b/lib/chef/resource/env.rb
index f96db899e8..d74b4feee0 100644
--- a/lib/chef/resource/env.rb
+++ b/lib/chef/resource/env.rb
@@ -25,7 +25,7 @@ class Chef
state_attrs :value
- resource_name :env
+ use_automatic_resource_name
provides :env, os: "windows"
def initialize(name, run_context=nil)
diff --git a/lib/chef/resource/erl_call.rb b/lib/chef/resource/erl_call.rb
index 8bf0ed19e6..c6d45c7aca 100644
--- a/lib/chef/resource/erl_call.rb
+++ b/lib/chef/resource/erl_call.rb
@@ -23,7 +23,7 @@ require 'chef/provider/erl_call'
class Chef
class Resource
class ErlCall < Chef::Resource
- resource_name :erl_call
+ use_automatic_resource_name
# erl_call : http://erlang.org/doc/man/erl_call.html
diff --git a/lib/chef/resource/execute.rb b/lib/chef/resource/execute.rb
index 7661fabd5c..c0263501c5 100644
--- a/lib/chef/resource/execute.rb
+++ b/lib/chef/resource/execute.rb
@@ -23,7 +23,7 @@ require 'chef/provider/execute'
class Chef
class Resource
class Execute < Chef::Resource
- resource_name :execute
+ use_automatic_resource_name
identity_attr :command
diff --git a/lib/chef/resource/file.rb b/lib/chef/resource/file.rb
index 607bc5d277..32fd984f8c 100644
--- a/lib/chef/resource/file.rb
+++ b/lib/chef/resource/file.rb
@@ -47,7 +47,7 @@ class Chef
# @returns [String] Checksum of the file we actually rendered
attr_accessor :final_checksum
- resource_name :file
+ use_automatic_resource_name
def initialize(name, run_context=nil)
super
diff --git a/lib/chef/resource/freebsd_package.rb b/lib/chef/resource/freebsd_package.rb
index 81b16dd846..f89e1813b9 100644
--- a/lib/chef/resource/freebsd_package.rb
+++ b/lib/chef/resource/freebsd_package.rb
@@ -29,7 +29,7 @@ class Chef
class FreebsdPackage < Chef::Resource::Package
include Chef::Mixin::ShellOut
- resource_name :freebsd_package
+ use_automatic_resource_name
provides :package, platform: "freebsd"
def after_created
diff --git a/lib/chef/resource/gem_package.rb b/lib/chef/resource/gem_package.rb
index 45e9ab2ab7..5bd3a89100 100644
--- a/lib/chef/resource/gem_package.rb
+++ b/lib/chef/resource/gem_package.rb
@@ -22,7 +22,7 @@ class Chef
class Resource
class GemPackage < Chef::Resource::Package
- resource_name :gem_package
+ use_automatic_resource_name
def initialize(name, run_context=nil)
super
diff --git a/lib/chef/resource/git.rb b/lib/chef/resource/git.rb
index 927bde5073..1229914766 100644
--- a/lib/chef/resource/git.rb
+++ b/lib/chef/resource/git.rb
@@ -22,7 +22,7 @@ class Chef
class Resource
class Git < Chef::Resource::Scm
- resource_name :git
+ use_automatic_resource_name
def initialize(name, run_context=nil)
super
diff --git a/lib/chef/resource/group.rb b/lib/chef/resource/group.rb
index cc4690983b..64062dbe8f 100644
--- a/lib/chef/resource/group.rb
+++ b/lib/chef/resource/group.rb
@@ -25,7 +25,7 @@ class Chef
state_attrs :members
- resource_name :group
+ use_automatic_resource_name
def initialize(name, run_context=nil)
super
diff --git a/lib/chef/resource/homebrew_package.rb b/lib/chef/resource/homebrew_package.rb
index 993f083359..fe0bd89ced 100644
--- a/lib/chef/resource/homebrew_package.rb
+++ b/lib/chef/resource/homebrew_package.rb
@@ -25,7 +25,7 @@ class Chef
class Resource
class HomebrewPackage < Chef::Resource::Package
- resource_name :homebrew_package
+ use_automatic_resource_name
provides :package, os: "darwin"
def initialize(name, run_context=nil)
diff --git a/lib/chef/resource/http_request.rb b/lib/chef/resource/http_request.rb
index 5fde286814..ea22a26456 100644
--- a/lib/chef/resource/http_request.rb
+++ b/lib/chef/resource/http_request.rb
@@ -23,7 +23,7 @@ require 'chef/provider/http_request'
class Chef
class Resource
class HttpRequest < Chef::Resource
- resource_name :http_request
+ use_automatic_resource_name
identity_attr :url
diff --git a/lib/chef/resource/ifconfig.rb b/lib/chef/resource/ifconfig.rb
index 2976484ea1..18a688c2a5 100644
--- a/lib/chef/resource/ifconfig.rb
+++ b/lib/chef/resource/ifconfig.rb
@@ -22,7 +22,7 @@ require 'chef/resource'
class Chef
class Resource
class Ifconfig < Chef::Resource
- resource_name :ifconfig
+ use_automatic_resource_name
identity_attr :device
diff --git a/lib/chef/resource/ips_package.rb b/lib/chef/resource/ips_package.rb
index 70c023d510..93b554eb6c 100644
--- a/lib/chef/resource/ips_package.rb
+++ b/lib/chef/resource/ips_package.rb
@@ -23,7 +23,7 @@ class Chef
class Resource
class IpsPackage < ::Chef::Resource::Package
- resource_name :ips_package
+ use_automatic_resource_name
provides :ips_package, os: "solaris2"
def initialize(name, run_context = nil)
diff --git a/lib/chef/resource/link.rb b/lib/chef/resource/link.rb
index 715e468625..84a2b94ca1 100644
--- a/lib/chef/resource/link.rb
+++ b/lib/chef/resource/link.rb
@@ -25,7 +25,7 @@ class Chef
class Link < Chef::Resource
include Chef::Mixin::Securable
- resource_name :link
+ use_automatic_resource_name
identity_attr :target_file
diff --git a/lib/chef/resource/log.rb b/lib/chef/resource/log.rb
index 639493a795..5b4081b0fe 100644
--- a/lib/chef/resource/log.rb
+++ b/lib/chef/resource/log.rb
@@ -23,7 +23,7 @@ require 'chef/provider/log'
class Chef
class Resource
class Log < Chef::Resource
- resource_name :log
+ use_automatic_resource_name
identity_attr :message
diff --git a/lib/chef/resource/lwrp_base.rb b/lib/chef/resource/lwrp_base.rb
index dbb14a1a02..129fc38d6f 100644
--- a/lib/chef/resource/lwrp_base.rb
+++ b/lib/chef/resource/lwrp_base.rb
@@ -53,7 +53,7 @@ class Chef
# We load the class first to give it a chance to set its own name
resource_class = Class.new(self)
- resource_class.provides resource_name.to_sym
+ resource_class.resource_name resource_name.to_sym
resource_class.run_context = run_context
resource_class.class_from_file(filename)
diff --git a/lib/chef/resource/macosx_service.rb b/lib/chef/resource/macosx_service.rb
index f2893d78da..29da2e6309 100644
--- a/lib/chef/resource/macosx_service.rb
+++ b/lib/chef/resource/macosx_service.rb
@@ -22,7 +22,7 @@ class Chef
class Resource
class MacosxService < Chef::Resource::Service
- resource_name :macosx_service
+ use_automatic_resource_name
provides :macosx_service, os: "darwin"
provides :service, os: "darwin"
diff --git a/lib/chef/resource/macports_package.rb b/lib/chef/resource/macports_package.rb
index 583965a18a..3ccf831cf2 100644
--- a/lib/chef/resource/macports_package.rb
+++ b/lib/chef/resource/macports_package.rb
@@ -20,7 +20,7 @@ class Chef
class Resource
class MacportsPackage < Chef::Resource::Package
- resource_name :macports_package
+ use_automatic_resource_name
provides :package, os: "darwin"
end
end
diff --git a/lib/chef/resource/mdadm.rb b/lib/chef/resource/mdadm.rb
index e30452a113..8f19410b9c 100644
--- a/lib/chef/resource/mdadm.rb
+++ b/lib/chef/resource/mdadm.rb
@@ -27,7 +27,7 @@ class Chef
state_attrs :devices, :level, :chunk
- resource_name :mdadm
+ use_automatic_resource_name
def initialize(name, run_context=nil)
super
diff --git a/lib/chef/resource/mount.rb b/lib/chef/resource/mount.rb
index 193be16c68..f8a0cd157b 100644
--- a/lib/chef/resource/mount.rb
+++ b/lib/chef/resource/mount.rb
@@ -27,7 +27,7 @@ class Chef
state_attrs :mount_point, :device_type, :fstype, :username, :password, :domain
- resource_name :mount
+ use_automatic_resource_name
def initialize(name, run_context=nil)
super
diff --git a/lib/chef/resource/ohai.rb b/lib/chef/resource/ohai.rb
index 7451b1b84e..be24e97bde 100644
--- a/lib/chef/resource/ohai.rb
+++ b/lib/chef/resource/ohai.rb
@@ -20,7 +20,7 @@
class Chef
class Resource
class Ohai < Chef::Resource
- resource_name :ohai
+ use_automatic_resource_name
identity_attr :name
diff --git a/lib/chef/resource/openbsd_package.rb b/lib/chef/resource/openbsd_package.rb
index ad377afedd..1071958cd2 100644
--- a/lib/chef/resource/openbsd_package.rb
+++ b/lib/chef/resource/openbsd_package.rb
@@ -28,7 +28,7 @@ class Chef
class OpenbsdPackage < Chef::Resource::Package
include Chef::Mixin::ShellOut
- resource_name :openbsd_package
+ use_automatic_resource_name
provides :package, os: "openbsd"
def after_created
diff --git a/lib/chef/resource/package.rb b/lib/chef/resource/package.rb
index ec7e1e4862..0f4a5359ae 100644
--- a/lib/chef/resource/package.rb
+++ b/lib/chef/resource/package.rb
@@ -22,7 +22,7 @@ require 'chef/resource'
class Chef
class Resource
class Package < Chef::Resource
- resource_name :package
+ use_automatic_resource_name
identity_attr :package_name
diff --git a/lib/chef/resource/pacman_package.rb b/lib/chef/resource/pacman_package.rb
index 2f15655e52..222fb3c78e 100644
--- a/lib/chef/resource/pacman_package.rb
+++ b/lib/chef/resource/pacman_package.rb
@@ -22,7 +22,7 @@ class Chef
class Resource
class PacmanPackage < Chef::Resource::Package
- resource_name :pacman_package
+ use_automatic_resource_name
provides :pacman_package, os: "linux"
end
diff --git a/lib/chef/resource/paludis_package.rb b/lib/chef/resource/paludis_package.rb
index 67c1dbde0b..0907ba71a9 100644
--- a/lib/chef/resource/paludis_package.rb
+++ b/lib/chef/resource/paludis_package.rb
@@ -23,7 +23,7 @@ class Chef
class Resource
class PaludisPackage < Chef::Resource::Package
- resource_name :paludis_package
+ use_automatic_resource_name
provides :paludis_package, os: "linux"
def initialize(name, run_context=nil)
diff --git a/lib/chef/resource/perl.rb b/lib/chef/resource/perl.rb
index d4c7de694b..6870f487eb 100644
--- a/lib/chef/resource/perl.rb
+++ b/lib/chef/resource/perl.rb
@@ -22,7 +22,7 @@ require 'chef/provider/script'
class Chef
class Resource
class Perl < Chef::Resource::Script
- resource_name :perl
+ use_automatic_resource_name
def initialize(name, run_context=nil)
super
diff --git a/lib/chef/resource/portage_package.rb b/lib/chef/resource/portage_package.rb
index 34e1e91c2e..009a525d22 100644
--- a/lib/chef/resource/portage_package.rb
+++ b/lib/chef/resource/portage_package.rb
@@ -21,7 +21,7 @@ require 'chef/resource/package'
class Chef
class Resource
class PortagePackage < Chef::Resource::Package
- resource_name :portage_package
+ use_automatic_resource_name
def initialize(name, run_context=nil)
super
diff --git a/lib/chef/resource/powershell_script.rb b/lib/chef/resource/powershell_script.rb
index abf59b80a9..a3a24fce7f 100644
--- a/lib/chef/resource/powershell_script.rb
+++ b/lib/chef/resource/powershell_script.rb
@@ -21,7 +21,7 @@ class Chef
class Resource
class PowershellScript < Chef::Resource::WindowsScript
- resource_name :powershell_script
+ use_automatic_resource_name
provides :powershell_script, os: "windows"
def initialize(name, run_context=nil)
diff --git a/lib/chef/resource/python.rb b/lib/chef/resource/python.rb
index 3e9930ecab..5c120d7d27 100644
--- a/lib/chef/resource/python.rb
+++ b/lib/chef/resource/python.rb
@@ -21,7 +21,7 @@ require 'chef/provider/script'
class Chef
class Resource
class Python < Chef::Resource::Script
- resource_name :python
+ use_automatic_resource_name
def initialize(name, run_context=nil)
super
diff --git a/lib/chef/resource/reboot.rb b/lib/chef/resource/reboot.rb
index 337418e8d6..c2a4ff29e2 100644
--- a/lib/chef/resource/reboot.rb
+++ b/lib/chef/resource/reboot.rb
@@ -24,7 +24,7 @@ require 'chef/resource'
class Chef
class Resource
class Reboot < Chef::Resource
- resource_name :reboot
+ use_automatic_resource_name
def initialize(name, run_context=nil)
super
diff --git a/lib/chef/resource/registry_key.rb b/lib/chef/resource/registry_key.rb
index ad57116d94..5a700e5365 100644
--- a/lib/chef/resource/registry_key.rb
+++ b/lib/chef/resource/registry_key.rb
@@ -22,7 +22,7 @@ require 'chef/digester'
class Chef
class Resource
class RegistryKey < Chef::Resource
- resource_name :registry_key
+ use_automatic_resource_name
identity_attr :key
state_attrs :values
diff --git a/lib/chef/resource/remote_directory.rb b/lib/chef/resource/remote_directory.rb
index 9fd204cf85..a35e0995b0 100644
--- a/lib/chef/resource/remote_directory.rb
+++ b/lib/chef/resource/remote_directory.rb
@@ -26,7 +26,7 @@ class Chef
class RemoteDirectory < Chef::Resource::Directory
include Chef::Mixin::Securable
- resource_name :remote_directory
+ use_automatic_resource_name
identity_attr :path
diff --git a/lib/chef/resource/remote_file.rb b/lib/chef/resource/remote_file.rb
index 3387ff36ab..603151357c 100644
--- a/lib/chef/resource/remote_file.rb
+++ b/lib/chef/resource/remote_file.rb
@@ -28,7 +28,7 @@ class Chef
class RemoteFile < Chef::Resource::File
include Chef::Mixin::Securable
- resource_name :remote_file
+ use_automatic_resource_name
def initialize(name, run_context=nil)
super
diff --git a/lib/chef/resource/route.rb b/lib/chef/resource/route.rb
index 805678a85a..aca2a52e87 100644
--- a/lib/chef/resource/route.rb
+++ b/lib/chef/resource/route.rb
@@ -22,7 +22,7 @@ require 'chef/resource'
class Chef
class Resource
class Route < Chef::Resource
- resource_name :route
+ use_automatic_resource_name
identity_attr :target
diff --git a/lib/chef/resource/rpm_package.rb b/lib/chef/resource/rpm_package.rb
index ff4d087597..67a6c156d8 100644
--- a/lib/chef/resource/rpm_package.rb
+++ b/lib/chef/resource/rpm_package.rb
@@ -23,7 +23,7 @@ class Chef
class Resource
class RpmPackage < Chef::Resource::Package
- resource_name :rpm_package
+ use_automatic_resource_name
provides :rpm_package, os: [ "linux", "aix" ]
def initialize(name, run_context=nil)
diff --git a/lib/chef/resource/ruby.rb b/lib/chef/resource/ruby.rb
index 23c5931824..759955da42 100644
--- a/lib/chef/resource/ruby.rb
+++ b/lib/chef/resource/ruby.rb
@@ -22,7 +22,7 @@ require 'chef/provider/script'
class Chef
class Resource
class Ruby < Chef::Resource::Script
- resource_name :ruby
+ use_automatic_resource_name
def initialize(name, run_context=nil)
super
diff --git a/lib/chef/resource/ruby_block.rb b/lib/chef/resource/ruby_block.rb
index fb5a39f523..e4667533f2 100644
--- a/lib/chef/resource/ruby_block.rb
+++ b/lib/chef/resource/ruby_block.rb
@@ -23,7 +23,7 @@ require 'chef/provider/ruby_block'
class Chef
class Resource
class RubyBlock < Chef::Resource
- resource_name :ruby_block
+ use_automatic_resource_name
identity_attr :block_name
diff --git a/lib/chef/resource/scm.rb b/lib/chef/resource/scm.rb
index 9326fcca45..c97090d0a5 100644
--- a/lib/chef/resource/scm.rb
+++ b/lib/chef/resource/scm.rb
@@ -22,7 +22,7 @@ require 'chef/resource'
class Chef
class Resource
class Scm < Chef::Resource
- resource_name :scm
+ use_automatic_resource_name
identity_attr :destination
diff --git a/lib/chef/resource/script.rb b/lib/chef/resource/script.rb
index 6568d20ac5..f3d3ef01f4 100644
--- a/lib/chef/resource/script.rb
+++ b/lib/chef/resource/script.rb
@@ -23,7 +23,7 @@ require 'chef/provider/script'
class Chef
class Resource
class Script < Chef::Resource::Execute
- resource_name :script
+ use_automatic_resource_name
# Chef-13: go back to using :name as the identity attr
identity_attr :command
diff --git a/lib/chef/resource/service.rb b/lib/chef/resource/service.rb
index 433c329356..6ef203db3b 100644
--- a/lib/chef/resource/service.rb
+++ b/lib/chef/resource/service.rb
@@ -22,7 +22,7 @@ require 'chef/resource'
class Chef
class Resource
class Service < Chef::Resource
- resource_name :service
+ use_automatic_resource_name
identity_attr :service_name
diff --git a/lib/chef/resource/smartos_package.rb b/lib/chef/resource/smartos_package.rb
index 71e0b98b82..7460f0f687 100644
--- a/lib/chef/resource/smartos_package.rb
+++ b/lib/chef/resource/smartos_package.rb
@@ -23,7 +23,7 @@ class Chef
class Resource
class SmartosPackage < Chef::Resource::Package
- resource_name :smartos_package
+ use_automatic_resource_name
provides :package, os: "solaris2", platform_family: "smartos"
end
diff --git a/lib/chef/resource/solaris_package.rb b/lib/chef/resource/solaris_package.rb
index f247290f95..545e783b75 100644
--- a/lib/chef/resource/solaris_package.rb
+++ b/lib/chef/resource/solaris_package.rb
@@ -24,7 +24,7 @@ class Chef
class Resource
class SolarisPackage < Chef::Resource::Package
- resource_name :solaris_package
+ use_automatic_resource_name
provides :package, os: "solaris2", platform_family: "nexentacore"
provides :package, os: "solaris2", platform_family: "solaris2" do |node|
# on >= Solaris 11 we default to IPS packages instead
diff --git a/lib/chef/resource/subversion.rb b/lib/chef/resource/subversion.rb
index 7af42d30b0..f1b0391a8c 100644
--- a/lib/chef/resource/subversion.rb
+++ b/lib/chef/resource/subversion.rb
@@ -22,7 +22,7 @@ require "chef/resource/scm"
class Chef
class Resource
class Subversion < Chef::Resource::Scm
- resource_name :subversion
+ use_automatic_resource_name
def initialize(name, run_context=nil)
super
diff --git a/lib/chef/resource/template.rb b/lib/chef/resource/template.rb
index 6fb808127c..2c7ade6c29 100644
--- a/lib/chef/resource/template.rb
+++ b/lib/chef/resource/template.rb
@@ -27,7 +27,7 @@ class Chef
class Template < Chef::Resource::File
include Chef::Mixin::Securable
- resource_name :template
+ use_automatic_resource_name
attr_reader :inline_helper_blocks
attr_reader :inline_helper_modules
diff --git a/lib/chef/resource/timestamped_deploy.rb b/lib/chef/resource/timestamped_deploy.rb
index 6fa5544d77..15ac296f78 100644
--- a/lib/chef/resource/timestamped_deploy.rb
+++ b/lib/chef/resource/timestamped_deploy.rb
@@ -21,7 +21,7 @@ class Chef
# Convenience class for using the deploy resource with the timestamped
# deployment strategy (provider)
class TimestampedDeploy < Chef::Resource::Deploy
- resource_name :timestamped_deploy
+ use_automatic_resource_name
end
end
end
diff --git a/lib/chef/resource/user.rb b/lib/chef/resource/user.rb
index 6566e52c99..b762001d4b 100644
--- a/lib/chef/resource/user.rb
+++ b/lib/chef/resource/user.rb
@@ -26,7 +26,7 @@ class Chef
state_attrs :uid, :gid, :home
- resource_name :user
+ use_automatic_resource_name
def initialize(name, run_context=nil)
super
diff --git a/lib/chef/resource/whyrun_safe_ruby_block.rb b/lib/chef/resource/whyrun_safe_ruby_block.rb
index 8c6cd69b1a..0ade9c981f 100644
--- a/lib/chef/resource/whyrun_safe_ruby_block.rb
+++ b/lib/chef/resource/whyrun_safe_ruby_block.rb
@@ -20,7 +20,7 @@ class Chef
class Resource
class WhyrunSafeRubyBlock < Chef::Resource::RubyBlock
- resource_name :whyrun_safe_ruby_block
+ use_automatic_resource_name
end
end
diff --git a/lib/chef/resource/windows_package.rb b/lib/chef/resource/windows_package.rb
index 9fe4cef2c9..8f9944a5af 100644
--- a/lib/chef/resource/windows_package.rb
+++ b/lib/chef/resource/windows_package.rb
@@ -26,7 +26,7 @@ class Chef
class WindowsPackage < Chef::Resource::Package
include Chef::Mixin::Uris
- resource_name :windows_package
+ use_automatic_resource_name
provides :windows_package, os: "windows"
provides :package, os: "windows"
diff --git a/lib/chef/resource/windows_service.rb b/lib/chef/resource/windows_service.rb
index eb748bd42b..3f62a67a82 100644
--- a/lib/chef/resource/windows_service.rb
+++ b/lib/chef/resource/windows_service.rb
@@ -25,7 +25,7 @@ class Chef
# Until #1773 is resolved, you need to manually specify the windows_service resource
# to use action :configure_startup and attribute startup_type
- resource_name :windows_service
+ use_automatic_resource_name
provides :windows_service, os: "windows"
provides :service, os: "windows"
diff --git a/lib/chef/resource/yum_package.rb b/lib/chef/resource/yum_package.rb
index ebafeeb25d..ae9c840582 100644
--- a/lib/chef/resource/yum_package.rb
+++ b/lib/chef/resource/yum_package.rb
@@ -23,7 +23,7 @@ class Chef
class Resource
class YumPackage < Chef::Resource::Package
- resource_name :yum_package
+ use_automatic_resource_name
provides :package, os: "linux", platform_family: [ "rhel", "fedora" ]
def initialize(name, run_context=nil)
diff --git a/spec/integration/recipes/recipe_dsl_spec.rb b/spec/integration/recipes/recipe_dsl_spec.rb
index 3d31b87ffb..c79c20cd7d 100644
--- a/spec/integration/recipes/recipe_dsl_spec.rb
+++ b/spec/integration/recipes/recipe_dsl_spec.rb
@@ -58,7 +58,6 @@ describe "Recipe DSL methods" do
@allowed_actions = [ :create ]
@action = :create
end
- resource_name 'backcompat_thingy'
end
class Chef::Provider::BackcompatThingy < Chef::Provider
def load_current_resource
@@ -84,6 +83,7 @@ describe "Recipe DSL methods" do
before(:context) {
class RecipeDSLSpecNamespace::BackcompatThingy < BaseThingy
+ provides :backcompat_thingy
resource_name :backcompat_thingy
end
diff --git a/spec/integration/recipes/resource_definition_spec.rb b/spec/integration/recipes/resource_definition_spec.rb
index da92bb18fa..4e5bc53428 100644
--- a/spec/integration/recipes/resource_definition_spec.rb
+++ b/spec/integration/recipes/resource_definition_spec.rb
@@ -3,13 +3,10 @@ require 'support/shared/integration/integration_helper'
describe "Resource definition" do
include IntegrationSupport
- context "With a resource with no resource_name or provides line" do
- before do
- Chef::Config[:treat_deprecation_warnings_as_errors] = false
- end
-
+ context "With a resource with only provides lines and no resource_name" do
before(:context) {
- class Chef::Resource::ResourceDefinitionNoNameTest < Chef::Resource
+ class ResourceDefinitionNoNameTest < Chef::Resource
+ provides :resource_definition_no_name_test
end
}
it "Creating said resource with the resource builder fails with an exception" do
diff --git a/spec/support/lib/chef/resource/cat.rb b/spec/support/lib/chef/resource/cat.rb
index ac8ad2953f..9bfaebf07b 100644
--- a/spec/support/lib/chef/resource/cat.rb
+++ b/spec/support/lib/chef/resource/cat.rb
@@ -19,7 +19,7 @@
class Chef
class Resource
class Cat < Chef::Resource
- resource_name :cat
+ use_automatic_resource_name
attr_accessor :action
diff --git a/spec/support/lib/chef/resource/one_two_three_four.rb b/spec/support/lib/chef/resource/one_two_three_four.rb
index 52fe8be54d..4543744a28 100644
--- a/spec/support/lib/chef/resource/one_two_three_four.rb
+++ b/spec/support/lib/chef/resource/one_two_three_four.rb
@@ -19,7 +19,7 @@
class Chef
class Resource
class OneTwoThreeFour < Chef::Resource
- resource_name :one_two_three_four
+ use_automatic_resource_name
attr_reader :i_can_count
diff --git a/spec/support/lib/chef/resource/with_state.rb b/spec/support/lib/chef/resource/with_state.rb
index 91051cca58..efff2e7c12 100644
--- a/spec/support/lib/chef/resource/with_state.rb
+++ b/spec/support/lib/chef/resource/with_state.rb
@@ -22,7 +22,7 @@ require 'chef/json_compat'
class Chef
class Resource
class WithState < Chef::Resource
- resource_name :with_state
+ use_automatic_resource_name
attr_accessor :state
end
diff --git a/spec/support/lib/chef/resource/zen_follower.rb b/spec/support/lib/chef/resource/zen_follower.rb
index bbeeeaaeb7..90d33e6039 100644
--- a/spec/support/lib/chef/resource/zen_follower.rb
+++ b/spec/support/lib/chef/resource/zen_follower.rb
@@ -21,7 +21,7 @@ require 'chef/json_compat'
class Chef
class Resource
class ZenFollower < Chef::Resource
- resource_name :zen_follower
+ use_automatic_resource_name
provides :follower, platform: "zen"
diff --git a/spec/support/lib/chef/resource/zen_master.rb b/spec/support/lib/chef/resource/zen_master.rb
index 8f3ff7b72d..ed5b1b3add 100644
--- a/spec/support/lib/chef/resource/zen_master.rb
+++ b/spec/support/lib/chef/resource/zen_master.rb
@@ -22,7 +22,7 @@ require 'chef/json_compat'
class Chef
class Resource
class ZenMaster < Chef::Resource
- resource_name :zen_master
+ use_automatic_resource_name
attr_reader :peace
diff --git a/spec/unit/recipe_spec.rb b/spec/unit/recipe_spec.rb
index 9c4fb49497..59d05298c3 100644
--- a/spec/unit/recipe_spec.rb
+++ b/spec/unit/recipe_spec.rb
@@ -121,6 +121,7 @@ describe Chef::Recipe do
it "locate resource for particular platform" do
ShaunTheSheep = Class.new(Chef::Resource)
+ ShaunTheSheep.use_automatic_resource_name
ShaunTheSheep.provides :laughter, :on_platforms => ["television"]
node.automatic[:platform] = "television"
node.automatic[:platform_version] = "123"
@@ -131,6 +132,7 @@ describe Chef::Recipe do
it "locate a resource for all platforms" do
YourMom = Class.new(Chef::Resource)
+ YourMom.use_automatic_resource_name
YourMom.provides :love_and_caring
res = recipe.love_and_caring "mommy"
expect(res.name).to eql("mommy")
@@ -141,8 +143,10 @@ describe Chef::Recipe do
before do
node.automatic[:platform] = "nbc_sports"
Sounders = Class.new(Chef::Resource)
+ Sounders.use_automatic_resource_name
Sounders.provides :football, platform: "nbc_sports"
TottenhamHotspur = Class.new(Chef::Resource)
+ TottenhamHotspur.use_automatic_resource_name
TottenhamHotspur.provides :football, platform: "nbc_sports"
end
diff --git a/spec/unit/resource_spec.rb b/spec/unit/resource_spec.rb
index 2e0a88f555..bc5567b73a 100644
--- a/spec/unit/resource_spec.rb
+++ b/spec/unit/resource_spec.rb
@@ -399,6 +399,20 @@ describe Chef::Resource do
expect(r.resource_name).to eq :blah
expect(r.declared_type).to eq :d
end
+ it "use_automatic_resource_name yields a resource name from the class name" do
+ class SelfResourceNameTestBlahDBlah4 < Chef::Resource
+ use_automatic_resource_name
+ end
+
+ c = SelfResourceNameTestBlahDBlah4
+
+ r = c.new('hi')
+ r.declared_type = :d
+ expect(c.resource_name).to eq :self_resource_name_test_blah_d_blah4
+ expect(r.resource_name).to eq :self_resource_name_test_blah_d_blah4
+ expect(r.declared_type).to eq :d
+
+ end
end
describe "is" do