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
ARRAY_METHODS =

Array-only methods that should not be flagged when collection is clearly an array

%i[first last take].freeze
ITERATION_METHODS =
%i[each map select find_all reject collect detect find_index flat_map].freeze

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

default_severity

Class Method Details

.detector_nameObject



29
30
31
# File 'lib/eager_eye/detectors/custom_method_query.rb', line 29

def self.detector_name
  :custom_method_query
end

Instance Method Details

#detect(ast, file_path) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/eager_eye/detectors/custom_method_query.rb', line 33

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

  @issues = []
  @file_path = file_path

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

  @issues
end