class RuboCop::Cop::Chef::Modernize::ActionMethodInResource

Use the custom resource language’s ‘action :my_action` blocks instead of creating actions with methods.

@example

#### incorrect
def action_create
 # :create action code here
end

#### correct
action :create do
 # :create action code here
end

Constants

MSG

Public Instance Methods

on_def(node) click to toggle source
# File lib/rubocop/cop/chef/modernize/action_method_in_resource.rb, line 43
def on_def(node)
  return unless node.method_name.to_s.start_with?('action_') # when we stop support for Ruby < 2.7 the .to_s can go away here
  return if node.arguments? # if they passed in arguments they may actually need this
  return if node.parent && includes_poise?(node.parent)

  add_offense(node, severity: :refactor) do |corrector|
    # @todo when we drop ruby 2.4 support we can convert this to use delete_suffix
    corrector.replace(node, node.source.gsub("def #{node.method_name}", "action :#{node.method_name.to_s.gsub(/^action_/, '')} do"))
  end
end