Class: RailsAiBridge::Introspector
- Inherits:
-
Object
- Object
- RailsAiBridge::Introspector
- Defined in:
- lib/rails_ai_bridge/introspector.rb,
lib/rails_ai_bridge/introspector/timed_runner.rb,
lib/rails_ai_bridge/introspector/parallel_runner.rb
Overview
Orchestrates all sub-introspectors to build a complete picture of the Rails application for AI consumption.
Depending on configuration, introspectors are run sequentially (default) or concurrently via ParallelRunner. Sequential runs are timed via TimedRunner so duration data is available in debug logs regardless of the execution strategy.
Defined Under Namespace
Classes: ParallelRunner, TimedRunner
Constant Summary collapse
- BUILTIN_INTROSPECTORS =
Registry of all built-in introspector classes, keyed by symbolic name.
The +:standard+ preset uses 9 of these; the +:full+ preset uses 26. Opt-in-only keys (e.g. +:database_stats+, +:non_ar_models+) are present here but excluded from both presets by default.
{ schema: Introspectors::SchemaIntrospector, models: Introspectors::ModelIntrospector, non_ar_models: Introspectors::NonArModelsIntrospector, routes: Introspectors::RouteIntrospector, jobs: Introspectors::JobIntrospector, gems: Introspectors::GemIntrospector, conventions: Introspectors::ConventionDetector, stimulus: Introspectors::StimulusIntrospector, database_stats: Introspectors::DatabaseStatsIntrospector, controllers: Introspectors::ControllerIntrospector, views: Introspectors::ViewIntrospector, turbo: Introspectors::TurboIntrospector, i18n: Introspectors::I18nIntrospector, config: Introspectors::ConfigIntrospector, active_storage: Introspectors::ActiveStorageIntrospector, action_text: Introspectors::ActionTextIntrospector, auth: Introspectors::AuthIntrospector, api: Introspectors::ApiIntrospector, tests: Introspectors::TestIntrospector, rake_tasks: Introspectors::RakeTaskIntrospector, assets: Introspectors::AssetPipelineIntrospector, devops: Introspectors::DevOpsIntrospector, action_mailbox: Introspectors::ActionMailboxIntrospector, migrations: Introspectors::MigrationIntrospector, seeds: Introspectors::SeedsIntrospector, middleware: Introspectors::MiddlewareIntrospector, engines: Introspectors::EngineIntrospector, multi_database: Introspectors::MultiDatabaseIntrospector, semantic: Introspectors::SemanticIntrospector }.freeze
Instance Attribute Summary collapse
-
#app ⇒ Rails::Application
readonly
The host application passed at construction.
-
#config ⇒ RailsAiBridge::Configuration
readonly
Active gem configuration.
Instance Method Summary collapse
-
#app_name ⇒ String
Returns the application name derived from the Rails application class.
-
#call(only: nil) ⇒ Hash
Runs all configured (or a specified subset of) introspectors and returns a unified context hash.
-
#initialize(app) ⇒ Introspector
constructor
A new instance of Introspector.
-
#resolve_introspector(name) ⇒ Object
Looks up and instantiates an introspector by name.
-
#selected_introspectors(only) ⇒ Array<Symbol>
Resolves the list of introspector keys to run.
Constructor Details
#initialize(app) ⇒ Introspector
Returns a new instance of Introspector.
27 28 29 30 |
# File 'lib/rails_ai_bridge/introspector.rb', line 27 def initialize(app) @app = app @config = RailsAiBridge.configuration end |
Instance Attribute Details
#app ⇒ Rails::Application (readonly)
Returns the host application passed at construction.
21 22 23 |
# File 'lib/rails_ai_bridge/introspector.rb', line 21 def app @app end |
#config ⇒ RailsAiBridge::Configuration (readonly)
Returns active gem configuration.
24 25 26 |
# File 'lib/rails_ai_bridge/introspector.rb', line 24 def config @config end |
Instance Method Details
#app_name ⇒ String
Returns the application name derived from the Rails application class.
Tries +module_parent_name+ first (Rails 6+), falling back to +deconstantize+ on the full class name.
104 105 106 107 108 109 110 |
# File 'lib/rails_ai_bridge/introspector.rb', line 104 def app_name if app.class.respond_to?(:module_parent_name) app.class.module_parent_name else app.class.name.deconstantize end end |
#call(only: nil) ⇒ Hash
Runs all configured (or a specified subset of) introspectors and returns a unified context hash.
Metadata keys (+:app_name+, +:ruby_version+, +:rails_version+, etc.) are always present. Introspector results are merged in at the top level, keyed by their symbolic name (e.g. +:schema+, +:routes+).
When parallel introspection is enabled and more than one introspector is requested, execution is delegated to ParallelRunner. Otherwise each introspector runs sequentially, wrapped by TimedRunner for observability.
46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/rails_ai_bridge/introspector.rb', line 46 def call(only: nil) context = names = selected_introspectors(only) results = if parallel_enabled? && names.size > 1 run_parallel(names) else run_sequential(names) end context.merge(results) end |
#resolve_introspector(name) ⇒ Object
Looks up and instantiates an introspector by name.
Checks +config.additional_introspectors+ before falling back to BUILTIN_INTROSPECTORS.
134 135 136 137 138 139 |
# File 'lib/rails_ai_bridge/introspector.rb', line 134 def resolve_introspector(name) introspector_class = config.additional_introspectors[name] || BUILTIN_INTROSPECTORS[name] raise ConfigurationError, "Unknown introspector: #{name}" unless introspector_class introspector_class.new(app) end |
#selected_introspectors(only) ⇒ Array<Symbol>
Resolves the list of introspector keys to run.
Returns +config.effective_introspectors+ when +only+ is blank; otherwise returns the compact, de-nilified version of +only+.
119 120 121 122 123 124 |
# File 'lib/rails_ai_bridge/introspector.rb', line 119 def selected_introspectors(only) names = Array(only).compact return config.effective_introspectors if names.empty? names end |