diff options
-rw-r--r-- | lib/chef/provider.rb | 9 | ||||
-rw-r--r-- | lib/chef/resource.rb | 39 |
2 files changed, 26 insertions, 22 deletions
diff --git a/lib/chef/provider.rb b/lib/chef/provider.rb index 03b546c09d..7cfddba0cb 100644 --- a/lib/chef/provider.rb +++ b/lib/chef/provider.rb @@ -423,9 +423,9 @@ class Chef module DeprecatedLWRPClass def const_missing(class_name) - if deprecated_constants[class_name.to_sym] + if Chef::Provider.deprecated_constants[class_name.to_sym] Chef.log_deprecation("Using an LWRP provider by its name (#{class_name}) directly is no longer supported in Chef 12 and will be removed. Use Chef::ProviderResolver.new(node, resource, action) instead.") - deprecated_constants[class_name.to_sym] + Chef::Provider.deprecated_constants[class_name.to_sym] else raise NameError, "uninitialized constant Chef::Provider::#{class_name}" end @@ -438,13 +438,12 @@ class Chef if Chef::Provider.const_defined?(class_name, false) Chef::Log.warn "Chef::Provider::#{class_name} already exists! Cannot create deprecation class for #{provider_class}" else - deprecated_constants[class_name.to_sym] = provider_class + Chef::Provider.deprecated_constants[class_name.to_sym] = provider_class end end - private - def deprecated_constants + raise "Deprecated constants should be called only on Chef::Provider" unless self == Chef::Provider @deprecated_constants ||= {} end end diff --git a/lib/chef/resource.rb b/lib/chef/resource.rb index 2633187690..262aa84781 100644 --- a/lib/chef/resource.rb +++ b/lib/chef/resource.rb @@ -1530,23 +1530,6 @@ class Chef end # @api private - def self.register_deprecated_lwrp_class(resource_class, class_name) - if Chef::Resource.const_defined?(class_name, false) - Chef::Log.warn "#{class_name} already exists! Deprecation class overwrites #{resource_class}" - Chef::Resource.send(:remove_const, class_name) - 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 - end - - def self.deprecated_constants - @deprecated_constants ||= {} - end - - # @api private def lookup_provider_constant(name, action = :nothing) begin self.class.provider_base.const_get(convert_to_class_name(name.to_s)) @@ -1559,6 +1542,27 @@ class Chef end end + module DeprecatedLWRPClass + + # @api private + def register_deprecated_lwrp_class(resource_class, class_name) + if Chef::Resource.const_defined?(class_name, false) + Chef::Log.warn "#{class_name} already exists! Deprecation class overwrites #{resource_class}" + Chef::Resource.send(:remove_const, class_name) + end + + if !Chef::Config[:treat_deprecation_warnings_as_errors] + Chef::Resource.const_set(class_name, resource_class) + Chef::Resource.deprecated_constants[class_name.to_sym] = resource_class + end + end + + def deprecated_constants + raise "Deprecated constants should be called only on Chef::Resource" unless self == Chef::Resource + @deprecated_constants ||= {} + end + end + private def self.remove_canonical_dsl @@ -1569,6 +1573,7 @@ class Chef end end end + extend DeprecatedLWRPClass end end |