Skip to content

Commit

Permalink
Get rid of warning when defining an LWRP
Browse files Browse the repository at this point in the history
  • Loading branch information
jkeiser committed Jun 23, 2015
1 parent 87e631c commit 35e07bb
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 20 deletions.
27 changes: 13 additions & 14 deletions lib/chef/resource.rb
Expand Up @@ -1318,23 +1318,22 @@ def self.register_deprecated_lwrp_class(resource_class, class_name)
# 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
Expand Down
8 changes: 2 additions & 6 deletions spec/integration/recipes/lwrp_spec.rb
Expand Up @@ -45,12 +45,8 @@
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 = <<EOM
* l_w_r_p_foo[me] action create (up to date)
EOM
expected = expected.lines.map { |l| l.chomp }.join("\n")
expect(actual).to include(expected)
expect(result.stdout).to match(/\* l_w_r_p_foo\[me\] action create \(up to date\)/)
expect(result.stdout).not_to match(/WARN: You are overriding l_w_r_p_foo/)
result.error!
end
end
Expand Down

0 comments on commit 35e07bb

Please sign in to comment.