Class: RuboCop::Cop::Captive::Rails::NoFindByInScope

Inherits:
RuboCop::Cop::Cop
  • Object
show all
Defined in:
lib/rubocop/cop/captive/rails/no_find_by_in_scope.rb

Overview

Avoid using ‘find_by` in a scope. Use `where` to return a collection or define a class method if you need a single record.

Constant Summary collapse

MSG =
"Avoid using `find_by` in a scope. Use `where` to return \
a collection or define a class method if you need a single record."

Instance Method Summary collapse

Instance Method Details

#on_block(node) ⇒ Object



21
22
23
24
25
# File 'lib/rubocop/cop/captive/rails/no_find_by_in_scope.rb', line 21

def on_block(node)
  find_by_in_scope?(node) do
    add_offense(node, message: MSG)
  end
end