Class: RuboCop::Cop::Chef::ChefDeprecations::NodeDeepFetch

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

Overview

The node.deep_fetch method has been removed from Chef-Sugar, and must be replaced by the node.read API.

Examples:


# bad
node.deep_fetch("foo")

# good
node.read("foo")

# bad
node.deep_fetch!("foo")

# good
node.read!("foo")

Constant Summary collapse

MSG =
'Do not use node.deep_fetch. Replace with node.read to keep identical behavior.'.freeze
MSG2 =
'Do not use node.deep_fetch!. Replace with node.read! to keep identical behavior.'.freeze

Instance Method Summary collapse

Instance Method Details

#autocorrect(node) ⇒ Object



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

def autocorrect(node)
  lambda do |corrector|
    corrector.replace(node.loc.selector, fix_name(node.method_name))
  end
end

#on_send(node) ⇒ Object



49
50
51
52
53
54
55
56
57
# File 'lib/rubocop/cop/chef/deprecation/node_deep_fetch.rb', line 49

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

  node_deep_fetch_bang?(node) do
    add_offense(node, location: :selector, message: MSG2, severity: :refactor)
  end
end