Class: RuboCop::Cop::Chef::ChefDeprecations::PartialSearchClassUsage

Inherits:
RuboCop::Cop
  • Object
show all
Defined in:
lib/rubocop/cop/chef/deprecation/partial_search_class_usage.rb

Overview

Legacy Chef::PartialSearch class usage should be updated to use the ‘search` helper instead with the `filter_result` key.

Examples:


# bad
::Chef::PartialSearch.new.search((:node, 'role:web',
  keys: { 'name' => [ 'name' ],
          'ip' => [ 'ipaddress' ],
          'kernel_version' => %w(kernel version),
            }
).each do |result|
  puts result['name']
  puts result['ip']
  puts result['kernel_version']
end

# good
search(:node, 'role:web',
  filter_result: { 'name' => [ 'name' ],
                   'ip' => [ 'ipaddress' ],
                   'kernel_version' => %w(kernel version),
            }
).each do |result|
  puts result['name']
  puts result['ip']
  puts result['kernel_version']
end

Constant Summary collapse

MSG =
'Legacy Chef::PartialSearch class usage should be updated to use the search helper instead with the filter_result key.'.freeze

Instance Method Summary collapse

Instance Method Details

#on_send(node) ⇒ Object



56
57
58
59
60
# File 'lib/rubocop/cop/chef/deprecation/partial_search_class_usage.rb', line 56

def on_send(node)
  partial_search_class?(node) do
    add_offense(node, location: :expression, message: MSG, severity: :refactor)
  end
end