Class: Deprecool::Finders::Rails::V8_2_0::ToSqlBinds

Inherits:
Deprecool::Finder show all
Defined in:
lib/deprecool/finders/rails/v8.2.0/to_sql_binds.rb

Instance Attribute Summary

Attributes inherited from Deprecool::Finder

#file_path, #source

Instance Method Summary collapse

Methods inherited from Deprecool::Finder

affected_version_range, classname, effort, hook_methods, id, inherited, #initialize

Methods included from PrismHelpers

#unwrap_arguments, #unwrap_array, #unwrap_children, #unwrap_class, #unwrap_parentheses

Constructor Details

This class inherits a constructor from Deprecool::Finder

Instance Method Details

#on_call_node(node) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/deprecool/finders/rails/v8.2.0/to_sql_binds.rb', line 19

def on_call_node(node)
  # to_sql is a method on an ActiveRecord::Base.connection
  # the first argument should be a string of sql
  # the second argument used to be an array of binds
  # == the second argument is now deprecated ==
  #
  # the name of the connection is likely to be connection, but that's unreliable
  # if a method called 'to_sql' is passed two arguments and the second is an
  # array that's probably good enough
  return unless node.name == :to_sql

  arguments_array = unwrap_arguments(node.arguments)
  return unless arguments_array && arguments_array[1]

  add_offense(node, confidence: :high)
end