Class: RailsAiContext::Introspectors::ModelIntrospector

Inherits:
Object
  • Object
show all
Defined in:
lib/rails_ai_context/introspectors/model_introspector.rb

Overview

Extracts ActiveRecord model metadata using a hybrid approach:

  • Rails reflection for runtime data (associations, validations, enums, table info)

  • Prism AST for source-level declarations (scopes, callbacks, macros, methods)

The AST layer replaces all regex/scan/match? source parsing with Prism::Dispatcher-based single-pass extraction via SourceIntrospector.

Constant Summary collapse

EXCLUDED_CALLBACKS =
%w[autosave_associated_records_for].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ ModelIntrospector

Returns a new instance of ModelIntrospector.



16
17
18
19
# File 'lib/rails_ai_context/introspectors/model_introspector.rb', line 16

def initialize(app)
  @app    = app
  @config = RailsAiContext.configuration
end

Instance Attribute Details

#appObject (readonly)

Returns the value of attribute app.



12
13
14
# File 'lib/rails_ai_context/introspectors/model_introspector.rb', line 12

def app
  @app
end

#configObject (readonly)

Returns the value of attribute config.



12
13
14
# File 'lib/rails_ai_context/introspectors/model_introspector.rb', line 12

def config
  @config
end

Instance Method Details

#callHash

Returns model metadata keyed by model name.

Returns:

  • (Hash)

    model metadata keyed by model name



22
23
24
25
26
27
28
29
30
31
# File 'lib/rails_ai_context/introspectors/model_introspector.rb', line 22

def call
  eager_load_models!
  models = discover_models

  models.each_with_object({}) do |model, hash|
    hash[model.name] = extract_model_details(model)
  rescue => e
    hash[model.name] = { error: e.message }
  end
end