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 =
Callback name prefixes omitted from generated model context to reduce framework noise.
%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 metadata map for all discovered ActiveRecord models.
-
#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.
Also prepares a path resolver so source-based metadata honors custom Rails path configuration.
18 19 20 21 22 |
# File 'lib/rails_ai_bridge/introspectors/model_introspector.rb', line 18 def initialize(app) @app = app @config = RailsAiBridge.configuration @path_resolver = PathResolver.new(app) 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 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.
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/rails_ai_bridge/introspectors/model_introspector.rb', line 31 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 |