Class: EagerEye::Detectors::CustomMethodQuery

Inherits:
Base
  • Object
show all
Defined in:
lib/eager_eye/detectors/custom_method_query.rb

Constant Summary collapse

QUERY_METHODS =
%i[where find_by find_by! exists? find first last take pluck ids count sum average minimum
maximum].freeze
SAFE_QUERY_METHODS =
%i[first last take count sum find size length ids].freeze
SAFE_TRANSFORM_METHODS =
%i[keys values split [] params sort pluck ids to_s to_a to_i chars bytes].freeze
ARRAY_COLUMN_SUFFIXES =
%w[_ids _tags _types _codes _names _values _arr].freeze
ITERATION_METHODS =
%i[each map select find_all reject collect detect find_index flat_map
find_each find_in_batches in_batches].freeze

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

default_severity

Class Method Details

.detector_nameObject



14
15
16
# File 'lib/eager_eye/detectors/custom_method_query.rb', line 14

def self.detector_name
  :custom_method_query
end

Instance Method Details

#detect(ast, file_path) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/eager_eye/detectors/custom_method_query.rb', line 18

def detect(ast, file_path)
  return [] unless ast

  @issues = []
  @file_path = file_path

  find_iteration_blocks(ast) do |block_body, block_var, collection, definitions|
    check_block_for_query_methods(block_body, block_var, collection_is_array?(collection, definitions))
  end

  @issues
end