Class: RailsLens::ModelSources::ActiveRecordSource

Inherits:
RailsLens::ModelSource show all
Defined in:
lib/rails_lens/model_sources/active_record_source.rb

Overview

Built-in model source for ActiveRecord models

Class Method Summary collapse

Class Method Details

.annotate_model(model, options = {}) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/rails_lens/model_sources/active_record_source.rb', line 32

def annotate_model(model, options = {})
  # Use the optimized connection-pooled annotation
  results = { annotated: [], skipped: [], failed: [] }

  # Group this single model by connection pool for consistency
  begin
    pool = model.connection_pool
    pool.with_connection do |connection|
      Schema::AnnotationManager.process_model_with_connection(model, connection, results, options)
    end
  rescue StandardError
    # Fallback without connection management
    Schema::AnnotationManager.process_model_with_connection(model, nil, results, options)
  end

  if results[:annotated].include?(model.name)
    { status: :annotated, model: model.name, file: model_file_path(model) }
  elsif results[:failed].any? { |f| f[:model] == model.name }
    failure = results[:failed].find { |f| f[:model] == model.name }
    { status: :failed, model: model.name, message: failure[:error] }
  else
    { status: :skipped, model: model.name }
  end
end

.file_patternsObject



28
29
30
# File 'lib/rails_lens/model_sources/active_record_source.rb', line 28

def file_patterns
  ['app/models/**/*.rb']
end

.models(options = {}) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/rails_lens/model_sources/active_record_source.rb', line 8

def models(options = {})
  # Convert models option to include option for ModelDetector
  opts = options.dup
  opts[:include] = opts.delete(:models) if opts[:models]

  models = ModelDetector.detect_models(opts)

  # Filter abstract classes based on options
  if opts[:include_abstract]
    # Include all models
  elsif opts[:abstract_only]
    models = models.select(&:abstract_class?)
  else
    # Default: exclude abstract classes
    models = models.reject(&:abstract_class?)
  end

  models
end

.remove_annotation(model) ⇒ Object



57
58
59
60
61
62
63
64
65
66
# File 'lib/rails_lens/model_sources/active_record_source.rb', line 57

def remove_annotation(model)
  manager = Schema::AnnotationManager.new(model)
  if manager.remove_annotations
    { status: :removed, model: model.name, file: model_file_path(model) }
  else
    { status: :skipped, model: model.name }
  end
rescue StandardError => e
  { status: :failed, model: model.name, message: e.message }
end

.source_nameObject



68
69
70
# File 'lib/rails_lens/model_sources/active_record_source.rb', line 68

def source_name
  'ActiveRecord'
end