class RuboCop::Cop::Chef::Ruby::UnlessDefinedRequire
Rubygems is VERY slow to require gems even if they've already been loaded. To work around this wrap your require statement with an `if defined?()` check.
Constants
- MSG
- REQUIRE_TO_CLASS
Public Instance Methods
on_send(node)
click to toggle source
# File lib/rubocop/cop/chef/ruby/unless_defined_require.rb, line 108 def on_send(node) require?(node) do |r| next if node.parent && node.parent.conditional? # catch both if and unless next unless REQUIRE_TO_CLASS[r] add_offense(node.loc.expression, message: MSG, severity: :refactor) do |corrector| corrector.replace(node.loc.expression, "#{node.source} unless defined?(#{REQUIRE_TO_CLASS[r]})") end end end