Class: RuboCop::Cop::Chef::Modernize::DatabagHelpers
- Extended by:
- AutoCorrector
- Defined in:
- lib/rubocop/cop/chef/modernize/databag_helpers.rb
Overview
Use the data_bag_item helper instead of Chef::DataBagItem.load or Chef::EncryptedDataBagItem.load.
Constant Summary collapse
- MSG =
'Use the `data_bag_item` helper instead of `Chef::DataBagItem.load` or `Chef::EncryptedDataBagItem.load`.'- RESTRICT_ON_SEND =
[:load].freeze
Instance Method Summary collapse
Methods inherited from Base
Instance Method Details
#on_send(node) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/rubocop/cop/chef/modernize/databag_helpers.rb', line 47 def on_send(node) data_bag_class_load?(node) do add_offense(node, severity: :refactor) do |corrector| # replace only the receiver and the .load selector, so that the arguments are left # exactly as written. rewriting node.source would also hit any argument that # happened to contain the class name, and would leave the leading :: of a scope # resolved ::Chef::DataBagItem.load behind corrector.replace(node.receiver.source_range.join(node.loc.selector), 'data_bag_item') end end end |