class RuboCop::Cop::Chef::Deprecations::ChefRewind

Use `delete_resource` or `edit_resource` helpers introduced in Chef Infra Client 12.10 instead of functionality in the deprecated `chef-rewind` gem

@example

chef_gem 'chef-rewind'

require 'chef/rewind'

rewind "user[postgres]" do
  home '/var/lib/pgsql/9.2'
  cookbook 'my-postgresql'
end

unwind "user[postgres]"

Constants

MAPPING
MSG
RESTRICT_ON_SEND

Public Instance Methods

on_block(node) click to toggle source
# File lib/rubocop/cop/chef/deprecation/chef_rewind.rb, line 86
def on_block(node)
  match_property_in_resource?(:chef_gem, 'package_name', node) do |pkg_name|
    next unless pkg_name.arguments&.first&.str_content == 'chef-rewind'
    add_offense(node, message: MSG, severity: :warning) do |corrector|
      corrector.remove(node) if pkg_name.arguments&.first&.str_content == 'chef-rewind'
    end
  end
end
on_send(node) click to toggle source
# File lib/rubocop/cop/chef/deprecation/chef_rewind.rb, line 65
def on_send(node)
  rewind_gem_install?(node) do
    add_offense(node, message: MSG, severity: :warning) do |corrector|
      node = node.parent if node.parent&.block_type? # make sure we get the whole block not just the method in the block
      corrector.remove(range_with_surrounding_space(range: node.loc.expression, side: :left))
    end
  end

  require_rewind?(node) do
    add_offense(node, message: MSG, severity: :warning) do |corrector|
      corrector.remove(range_with_surrounding_space(range: node.loc.expression, side: :left))
    end
  end

  rewind_resources?(node) do |string|
    add_offense(node, message: MSG, severity: :warning) do |corrector|
      corrector.replace(node, node.source.gsub(string.to_s, MAPPING[string]))
    end
  end
end