Class: RailsAiContext::Introspectors::ModelIntrospector
- Inherits:
-
Object
- Object
- RailsAiContext::Introspectors::ModelIntrospector
- 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
-
#app ⇒ Object
readonly
Returns the value of attribute app.
-
#config ⇒ Object
readonly
Returns the value of attribute config.
Instance Method Summary collapse
-
#call ⇒ Hash
Model metadata keyed by model name.
-
#initialize(app) ⇒ ModelIntrospector
constructor
A new instance of ModelIntrospector.
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
#app ⇒ Object (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 |
#config ⇒ Object (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
#call ⇒ Hash
Returns 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. } end end |