Class: RuboCop::Cop::Chef::Deprecations::DeprecatedPlatformMethods

Inherits:
Base
  • Object
show all
Defined in:
lib/rubocop/cop/chef/deprecation/deprecated_platform_methods.rb

Overview

Use ‘provider_for_action` or provides instead of the deprecated `Chef::Platform` methods in resources, which were removed in Chef Infra Client 13.

Examples:


### incorrect
resource = Chef::Resource::File.new("/tmp/foo.xyz", run_context)
provider = Chef::Platform.provider_for_resource(resource, :create)

resource = Chef::Resource::File.new("/tmp/foo.xyz", run_context)
provider = Chef::Platform.find_provider("ubuntu", "16.04", resource)

resource = Chef::Resource::File.new("/tmp/foo.xyz", run_context)
provider = Chef::Platform.find_provider_for_node(node, resource)

Chef::Platform.set :platform => :mac_os_x, :resource => :package, :provider => Chef::Provider::Package::Homebrew

### correct
resource = Chef::Resource::File.new("/tmp/foo.xyz", run_context)
provider = resource.provider_for_action(:create)

# provides :package, platform_family: 'mac_os_x'

Constant Summary collapse

MSG =
'Use provider_for_action or provides instead of the deprecated Chef::Platform methods in resources, which were removed in Chef Infra Client 13.'
RESTRICT_ON_SEND =
[:provider_for_resource, :find_provider, :find_provider_for_node, :set].freeze

Instance Method Summary collapse

Methods inherited from Base

#target_chef_version

Instance Method Details

#on_send(node) ⇒ Object



52
53
54
55
56
# File 'lib/rubocop/cop/chef/deprecation/deprecated_platform_methods.rb', line 52

def on_send(node)
  platform_method?(node) do
    add_offense(node, severity: :warning)
  end
end