Class: RuboCop::Cop::Airbnb::DefaultScope

Inherits:
Base
  • Object
show all
Defined in:
lib/rubocop/cop/airbnb/default_scope.rb

Overview

Cop to help prevent the scorge of Default Scopes from ActiveRecord. Once in place they are almost impossible to remove.

Constant Summary collapse

MSG =
'Avoid `default_scope`.  Default scopes make it difficult to '\
'refactor data access patterns since the scope becomes part '\
'of every query unless explicitly excluded, even when it is '\
'unnecessary or incidental to the desired logic.'.freeze

Instance Method Summary collapse

Instance Method Details

#on_send(node) ⇒ Object



12
13
14
15
16
# File 'lib/rubocop/cop/airbnb/default_scope.rb', line 12

def on_send(node)
  return unless node.command?(:default_scope)

  add_offense(node)
end