Class: EagerEye::Detectors::CountInIteration

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

Constant Summary collapse

COUNT_METHODS =

count always executes a COUNT query size and length use memory when collection is loaded

%i[count].freeze
ITERATION_METHODS =
%i[
  each map select find_all reject collect
  each_with_index each_with_object flat_map
].freeze

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

default_severity

Class Method Details

.detector_nameObject



15
16
17
# File 'lib/eager_eye/detectors/count_in_iteration.rb', line 15

def self.detector_name
  :count_in_iteration
end

Instance Method Details

#detect(ast, file_path) ⇒ Object



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

def detect(ast, file_path)
  @issues = []
  @file_path = file_path

  return @issues unless ast

  find_iteration_blocks(ast) do |block_body, block_var|
    check_for_count_calls(block_body, block_var)
  end

  @issues
end