class RuboCop::Cop::Rails::FindEach

User.all.find_each
# good
User.all.each
# bad
@example
change them to use ‘all.find_each` instead.
This cop is used to identify usages of `all.each` and

def autocorrect(node)

def autocorrect(node)
  ->(corrector) { corrector.replace(node.loc.selector, 'find_each') }
end

def ignored_by_find_each?(relation_method)

def ignored_by_find_each?(relation_method)
  # Active Record's #find_each ignores various extra parameters
  IGNORED_METHODS.include?(relation_method)
end

def method_chain(node)

def method_chain(node)
  [*node.descendants.select(&:send_type?), node].map(&:method_name)
end

def on_send(node)

def on_send(node)
  return unless node.receiver &&
                node.receiver.send_type? &&
                node.method?(:each)
  return unless SCOPE_METHODS.include?(node.receiver.method_name)
  return if method_chain(node).any? { |m| ignored_by_find_each?(m) }
  add_offense(node, location: :selector)
end