Class: RuboCop::Cop::Captive::StringWhereInScope
- Inherits:
-
RuboCop::Cop::Cop
- Object
- RuboCop::Cop::Cop
- RuboCop::Cop::Captive::StringWhereInScope
- Defined in:
- lib/rubocop/cop/captive/string_where_in_scope.rb
Overview
Prevents to use ‘where` with string that contains SQL apart from model. Like `where(’date > ?‘, Date.current)` there, you writing a part of SQL. That’s why it’s important to write this, into a model, in order to respect the MVC architecture
Constant Summary collapse
- MSG =
"The `where` method should be used in a scope in a model."
Instance Method Summary collapse
Instance Method Details
#on_send(node) ⇒ Object
27 28 29 30 31 32 33 34 |
# File 'lib/rubocop/cop/captive/string_where_in_scope.rb', line 27 def on_send(node) return unless where_with_string?(node) = node.arguments[0] return if &.hash_type? add_offense(, message: MSG) end |