Class: RuboCop::Cop::Chef::Deprecations::PartialSearchClassUsage

Inherits:
Base
  • 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:


### incorrect
::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

### correct
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.'
RESTRICT_ON_SEND =
[:new].freeze

Instance Method Summary collapse

Methods inherited from Base

#target_chef_version

Instance Method Details

#on_send(node) ⇒ Object



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

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