summaryrefslogtreecommitdiff
path: root/lib/chef/resource.rb
diff options
context:
space:
mode:
authorJay Mundrawala <jdmundrawala@gmail.com>2015-06-30 10:27:33 -0700
committerJay Mundrawala <jdmundrawala@gmail.com>2015-06-30 11:50:38 -0700
commitaed2d5eabd33a6f36df82da62b97e478596b88ab (patch)
tree0dc8741d25148c6f61fb6491040f7f9bd3def231 /lib/chef/resource.rb
parentf353e3b63432db39d74c66fb9fa4e90bb6c66695 (diff)
downloadchef-aed2d5eabd33a6f36df82da62b97e478596b88ab.tar.gz
Simplify Chef::Resource::MyLWRP deprecation
Our logic for creating the deprecation class was too complicated and had a lot of edge cases. Simplifying here to only deprecate when `:treat_deprecation_warnings_as_errors` is set. This means that warnings will no longer be printed, however this is a lot less risky.
Diffstat (limited to 'lib/chef/resource.rb')
-rw-r--r--lib/chef/resource.rb53
1 files changed, 4 insertions, 49 deletions
diff --git a/lib/chef/resource.rb b/lib/chef/resource.rb
index 0abf874044..696089fe3e 100644
--- a/lib/chef/resource.rb
+++ b/lib/chef/resource.rb
@@ -1499,56 +1499,11 @@ class Chef
Chef::Resource.send(:remove_const, class_name)
end
- # In order to generate deprecation warnings when you use Chef::Resource::MyLwrp,
- # we make a special subclass (identical in nearly all respects) of the
- # actual LWRP. When you say any of these, a deprecation warning will be
- # generated:
- #
- # - Chef::Resource::MyLwrp.new(...)
- # - resource.is_a?(Chef::Resource::MyLwrp)
- # - resource.kind_of?(Chef::Resource::MyLwrp)
- # - case resource
- # when Chef::Resource::MyLwrp
- # end
- #
- 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
- end
- 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
- resource_class.class_eval do
- define_method(:is_a?) do |other|
- other.is_a?(Module) && other === self
- end
- define_method(:kind_of?) do |other|
- other.is_a?(Module) && other === self
- end
+ if !Chef::Config[:treat_deprecation_warnings_as_errors]
+ Chef::Resource.const_set(class_name, resource_class)
+ deprecated_constants[class_name.to_sym] = resource_class
end
- resource_subclass.class_eval do
- define_singleton_method(:===) do |other|
- 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 is a superclass of all resource_class descendants.
- if self == resource_subclass && other.class <= resource_class
- return true
- end
- super(other)
- end
- end
- deprecated_constants[class_name.to_sym] = resource_subclass
+
end
def self.deprecated_constants