Class: Dbwatcher::Services::DiagramAnalyzers::ModelAssociationAnalyzer
- Inherits:
-
BaseAnalyzer
- Object
- BaseService
- BaseAnalyzer
- Dbwatcher::Services::DiagramAnalyzers::ModelAssociationAnalyzer
- Defined in:
- lib/dbwatcher/services/diagram_analyzers/model_association_analyzer.rb
Overview
Analyzes relationships based on ActiveRecord model associations
This service examines ActiveRecord models to detect associations between models that were involved in a session. It uses direct model enumeration from ActiveRecord::Base.descendants to ensure reliable model discovery.
Supported model scenarios:
-
Regular models with standard table names
-
Namespaced models (e.g., Admin::User)
-
Models with custom table names (using self.table_name)
-
Models from external gems and complex inheritance hierarchies
Instance Method Summary collapse
-
#analyze(_context) ⇒ Array<Hash>
Analyze model associations.
-
#analyzer_type ⇒ String
Get analyzer type.
-
#initialize(session = nil) ⇒ ModelAssociationAnalyzer
constructor
Initialize with session.
-
#transform_to_dataset(raw_data) ⇒ DiagramData::Dataset
Transform raw association data to Dataset.
Methods inherited from BaseAnalyzer
Methods inherited from BaseService
Methods included from Logging
#debug_enabled?, #log_debug, #log_error, #log_info, #log_warn
Constructor Details
#initialize(session = nil) ⇒ ModelAssociationAnalyzer
Initialize with session
34 35 36 37 38 39 40 41 42 |
# File 'lib/dbwatcher/services/diagram_analyzers/model_association_analyzer.rb', line 34 def initialize(session = nil) @session = session @session_tables = session ? extract_session_tables(session) : [] @model_discovery = ModelAnalysis::ModelDiscovery.new(@session_tables) @association_extractor = ModelAnalysis::AssociationExtractor.new(@session_tables) @dataset_builder = ModelAnalysis::DatasetBuilder.new @models = [] super() end |
Instance Method Details
#analyze(_context) ⇒ Array<Hash>
Analyze model associations
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/dbwatcher/services/diagram_analyzers/model_association_analyzer.rb', line 48 def analyze(_context) return [] unless models_available? @models = @model_discovery.discover return [] if @models.empty? Rails.logger.debug "ModelAssociationAnalyzer: Starting analysis with #{@models.length} models" associations = @association_extractor.extract_all(@models) if associations.empty? && @models.any? associations = @association_extractor.generate_placeholder_associations(@models) end log_analysis_results(associations) associations end |
#analyzer_type ⇒ String
Get analyzer type
75 76 77 |
# File 'lib/dbwatcher/services/diagram_analyzers/model_association_analyzer.rb', line 75 def analyzer_type "model_association" end |
#transform_to_dataset(raw_data) ⇒ DiagramData::Dataset
Transform raw association data to Dataset
68 69 70 |
# File 'lib/dbwatcher/services/diagram_analyzers/model_association_analyzer.rb', line 68 def transform_to_dataset(raw_data) @dataset_builder.build_from_associations(raw_data, @models) end |