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 =
%i[first last take].freeze
HASH_ARRAY_METHODS =
%i[keys values].freeze
STRING_ARRAY_METHODS =
%i[split].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



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

def self.detector_name
  :custom_method_query
end

Instance Method Details

#detect(ast, file_path) ⇒ Object



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

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