class RuboCop::Cop::Ezcater::RailsTopLevelSqlExecute
Use `execute` instead of `ActiveRecord::Base.connection.execute` in migrations. The latter is redundant and can bypass migration safety checks.
@example
# good execute("...") # bad ActiveRecord::Base.connection.execute("...")
Constants
- MSG
Public Instance Methods
autocorrect(node)
click to toggle source
# File lib/rubocop/cop/ezcater/rails_top_level_sql_execute.rb, line 33 def autocorrect(node) lambda do |corrector| range = Parser::Source::Range.new( node.source_range.source_buffer, node.source_range.begin_pos, node.source_range.end_pos ) corrector.replace(range, "execute(#{node.last_argument.source})") end end
on_send(node)
click to toggle source
# File lib/rubocop/cop/ezcater/rails_top_level_sql_execute.rb, line 27 def on_send(node) ar_connection_execute(node) do add_offense(node, location: :expression, message: MSG) end end