Class: RailsAiBridge::Introspectors::ModelIntrospector
- Inherits:
-
Object
- Object
- RailsAiBridge::Introspectors::ModelIntrospector
- Defined in:
- lib/rails_ai_bridge/introspectors/model_introspector.rb
Overview
Extracts ActiveRecord model metadata: associations, validations, scopes, enums, callbacks, and class-level configuration.
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<String, Hash>
Builds a hash of discovered ActiveRecord model metadata keyed by model name.
-
#initialize(app) ⇒ ModelIntrospector
constructor
Initializes the ModelIntrospector with the host Rails application and loads the library configuration.
Constructor Details
#initialize(app) ⇒ ModelIntrospector
Initializes the ModelIntrospector with the host Rails application and loads the library configuration.
15 16 17 18 |
# File 'lib/rails_ai_bridge/introspectors/model_introspector.rb', line 15 def initialize(app) @app = app @config = RailsAiBridge.configuration end |
Instance Attribute Details
#app ⇒ Object (readonly)
Returns the value of attribute app.
8 9 10 |
# File 'lib/rails_ai_bridge/introspectors/model_introspector.rb', line 8 def app @app end |
#config ⇒ Object (readonly)
Returns the value of attribute config.
8 9 10 |
# File 'lib/rails_ai_bridge/introspectors/model_introspector.rb', line 8 def config @config end |
Instance Method Details
#call ⇒ Hash<String, Hash>
Builds a hash of discovered ActiveRecord model metadata keyed by model name.
For each model, performs semantic classification and collects table name,
associations, validations, scopes, enums, callbacks, concerns, public methods,
and source-based macro signals; if extraction for a model raises, records
{ error: <message> } for that model.
Builds a metadata map for all discovered ActiveRecord models.
For each model, the map contains the extracted metadata hash; if extraction fails for a model,
its value will be a hash with an :error key and the error message.
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/rails_ai_bridge/introspectors/model_introspector.rb', line 32 def call eager_load_models! models = discover_models through_names = ModelSemanticClassifier.through_join_model_names classifier = ModelSemanticClassifier.new( core_model_names: config.core_models, through_model_names: through_names ) models.each_with_object({}) do |model, hash| hash[model.name] = extract_model_details(model, classifier) rescue StandardError => error hash[model.name] = { error: error. } end end |