Class: EagerEye::AssociationParser

Inherits:
Object
  • Object
show all
Defined in:
lib/eager_eye/association_parser.rb

Constant Summary collapse

ASSOCIATION_METHODS =
%i[has_many has_one belongs_to has_and_belongs_to_many].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeAssociationParser

Returns a new instance of AssociationParser.



9
10
11
12
13
# File 'lib/eager_eye/association_parser.rb', line 9

def initialize
  @preloaded_associations = {}
  @association_names = Set.new
  @associations_by_model = {}
end

Instance Attribute Details

#association_namesObject (readonly)

Returns the value of attribute association_names.



7
8
9
# File 'lib/eager_eye/association_parser.rb', line 7

def association_names
  @association_names
end

#associations_by_modelObject (readonly)

Returns the value of attribute associations_by_model.



7
8
9
# File 'lib/eager_eye/association_parser.rb', line 7

def associations_by_model
  @associations_by_model
end

#preloaded_associationsObject (readonly)

Returns the value of attribute preloaded_associations.



7
8
9
# File 'lib/eager_eye/association_parser.rb', line 7

def preloaded_associations
  @preloaded_associations
end

Instance Method Details

#parse_model(ast, model_name) ⇒ Object



15
16
17
18
19
20
21
22
# File 'lib/eager_eye/association_parser.rb', line 15

def parse_model(ast, model_name)
  return unless ast

  # Register the model even if it declares no associations, so callers can
  # distinguish "model has no associations" from "model unknown to parser".
  @associations_by_model[model_name] ||= Set.new
  traverse(ast, model_name)
end