Class: RuboCop::Cop::Rails::ArelStar
- Inherits:
-
Base
- Object
- Base
- RuboCop::Cop::Rails::ArelStar
- Extended by:
- AutoCorrector
- Defined in:
- lib/rubocop/cop/rails/arel_star.rb
Overview
Prevents usage of "*"
on an Arel::Table column reference.
Using arel_table["*"]
causes the outputted string to be a literal
quoted asterisk (e.g. my_model
.*
). This causes the
database to look for a column named *
(or "*"
) as opposed
to expanding the column list as one would likely expect.
Constant Summary collapse
- MSG =
'Use `Arel.star` instead of `"*"` for expanded column lists.'
- RESTRICT_ON_SEND =
%i[[]].freeze
Instance Method Summary collapse
Instance Method Details
#on_send(node) ⇒ Object
37 38 39 40 41 42 43 |
# File 'lib/rubocop/cop/rails/arel_star.rb', line 37 def on_send(node) return unless (star = star_bracket?(node)) add_offense(star) do |corrector| corrector.replace(star, 'Arel.star') end end |