Class: RailsAiBridge::Introspector
- Inherits:
-
Object
- Object
- RailsAiBridge::Introspector
- Defined in:
- lib/rails_ai_bridge/introspector.rb
Overview
Orchestrates all sub-introspectors to build a complete picture of the Rails application for AI consumption.
Constant Summary collapse
- BUILTIN_INTROSPECTORS =
{ 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 }.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
- #app_name ⇒ Object
-
#call(only: nil) ⇒ Hash
Run all configured introspectors and return unified context hash.
-
#initialize(app) ⇒ Introspector
constructor
A new instance of Introspector.
- #resolve_introspector(name) ⇒ Object
- #selected_introspectors(only) ⇒ Object
Constructor Details
#initialize(app) ⇒ Introspector
Returns a new instance of Introspector.
9 10 11 12 |
# File 'lib/rails_ai_bridge/introspector.rb', line 9 def initialize(app) @app = app @config = RailsAiBridge.configuration end |
Instance Attribute Details
#app ⇒ Object (readonly)
Returns the value of attribute app.
7 8 9 |
# File 'lib/rails_ai_bridge/introspector.rb', line 7 def app @app end |
#config ⇒ Object (readonly)
Returns the value of attribute config.
7 8 9 |
# File 'lib/rails_ai_bridge/introspector.rb', line 7 def config @config end |
Instance Method Details
#app_name ⇒ Object
70 71 72 73 74 75 76 |
# File 'lib/rails_ai_bridge/introspector.rb', line 70 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
Run all configured introspectors and return unified context hash
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/rails_ai_bridge/introspector.rb', line 18 def call(only: nil) context = { app_name: app_name, ruby_version: RUBY_VERSION, rails_version: Rails.version, environment: Rails.env, generated_at: Time.current.iso8601, generator: "rails-ai-bridge v#{RailsAiBridge::VERSION}" } selected_introspectors(only).each do |name| introspector = resolve_introspector(name) context[name] = introspector.call rescue StandardError => error context[name] = { error: error. } Rails.logger.warn "[rails-ai-bridge] #{name} introspection failed: #{error.}" end context end |
#resolve_introspector(name) ⇒ Object
85 86 87 88 89 90 |
# File 'lib/rails_ai_bridge/introspector.rb', line 85 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) ⇒ Object
78 79 80 81 82 83 |
# File 'lib/rails_ai_bridge/introspector.rb', line 78 def selected_introspectors(only) names = Array(only).compact return config.effective_introspectors if names.empty? names end |