From 35e07bb402a215389eb674045cec78364a64a779 Mon Sep 17 00:00:00 2001 From: John Keiser Date: Tue, 23 Jun 2015 12:04:19 -0700 Subject: Get rid of warning when defining an LWRP --- lib/chef/resource.rb | 27 +++++++++++++-------------- spec/integration/recipes/lwrp_spec.rb | 8 ++------ 2 files changed, 15 insertions(+), 20 deletions(-) diff --git a/lib/chef/resource.rb b/lib/chef/resource.rb index 418b0dc1ce..ed0dbb50a7 100644 --- a/lib/chef/resource.rb +++ b/lib/chef/resource.rb @@ -1318,23 +1318,22 @@ class Chef # when Chef::Resource::MyLwrp # end # - resource_subclass = class_eval <<-EOM, __FILE__, __LINE__+1 - class Chef::Resource::#{class_name} < resource_class - resource_name nil # we do not actually provide anything - def initialize(*args, &block) - Chef::Log.deprecation("Using an LWRP by its name (#{class_name}) directly is no longer supported in Chef 13 and will be removed. Use Chef::Resource.resource_for_node(node, name) instead.") + resource_subclass = Class.new(resource_class) do + resource_name nil # we do not actually provide anything + def initialize(*args, &block) + Chef::Log.deprecation("Using an LWRP by its name (#{self.class.name}) directly is no longer supported in Chef 13 and will be removed. Use Chef::Resource.resource_for_node(node, name) instead.") + super + end + def self.resource_name(*args) + if args.empty? + @resource_name ||= superclass.resource_name + else super end - def self.resource_name(*args) - if args.empty? - @resource_name ||= superclass.resource_name - else - super - end - end - self end - EOM + self + end + eval("Chef::Resource::#{class_name} = resource_subclass") # Make case, is_a and kind_of work with the new subclass, for backcompat. # Any subclass of Chef::Resource::ResourceClass is already a subclass of resource_class # Any subclass of resource_class is considered a subclass of Chef::Resource::ResourceClass diff --git a/spec/integration/recipes/lwrp_spec.rb b/spec/integration/recipes/lwrp_spec.rb index e93763fddc..7ecdfc7c3a 100644 --- a/spec/integration/recipes/lwrp_spec.rb +++ b/spec/integration/recipes/lwrp_spec.rb @@ -45,12 +45,8 @@ log_level :warn EOM result = shell_out("#{chef_client} -c \"#{path_to('config/client.rb')}\" --no-color -F doc -o 'l-w-r-p::default'", :cwd => chef_dir) - actual = result.stdout.lines.map { |l| l.chomp }.join("\n") - expected = <