Class: EagerEye::Detectors::SerializerNesting

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

Constant Summary collapse

SERIALIZER_PATTERNS =
%w[ActiveModel::Serializer ActiveModelSerializers::Model Blueprinter::Base Alba::Resource].freeze
ATTRIBUTE_METHODS =
%i[attribute field attributes].freeze
OBJECT_REFS =
%i[object record resource].freeze
ACTIVE_STORAGE_METHODS =
%i[attached? attach attachment attachments blob blobs purge purge_later variant
preview].freeze
HAS_MANY_ASSOCIATIONS =
%w[
  authors users owners creators admins members customers clients
  posts articles comments categories tags children companies organizations
  projects tasks items orders products accounts profiles settings
  images avatars photos attachments documents
].freeze

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

default_severity

Class Method Details

.detector_nameObject



18
19
20
# File 'lib/eager_eye/detectors/serializer_nesting.rb', line 18

def self.detector_name
  :serializer_nesting
end

Instance Method Details

#detect(ast, file_path) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/eager_eye/detectors/serializer_nesting.rb', line 22

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

  issues = []

  traverse_ast(ast) do |node|
    next unless serializer_class?(node)

    find_nested_associations(node, file_path, issues)
  end

  issues
end