Class: RailsAiContext::Introspector
- Inherits:
-
Object
- Object
- RailsAiContext::Introspector
- Defined in:
- lib/rails_ai_context/introspector.rb
Overview
Orchestrates all sub-introspectors to build a complete picture of the Rails application for AI consumption.
Constant Summary collapse
- INTROSPECTOR_MAP =
Single source of truth: symbol → introspector class. Used by both the dispatcher below AND the Configuration presets validation, so adding/renaming introspectors only requires one edit.
{ schema: Introspectors::SchemaIntrospector, models: Introspectors::ModelIntrospector, routes: Introspectors::RouteIntrospector, jobs: Introspectors::JobIntrospector, gems: Introspectors::GemIntrospector, conventions: Introspectors::ConventionIntrospector, stimulus: Introspectors::StimulusIntrospector, database_stats: Introspectors::DatabaseStatsIntrospector, controllers: Introspectors::ControllerIntrospector, views: Introspectors::ViewIntrospector, view_templates: Introspectors::ViewTemplateIntrospector, 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, components: Introspectors::ComponentIntrospector, performance: Introspectors::PerformanceIntrospector, frontend_frameworks: Introspectors::FrontendFrameworkIntrospector }.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
Run all configured introspectors and return unified context hash.
-
#initialize(app) ⇒ Introspector
constructor
A new instance of Introspector.
Constructor Details
#initialize(app) ⇒ Introspector
Returns a new instance of Introspector.
9 10 11 12 |
# File 'lib/rails_ai_context/introspector.rb', line 9 def initialize(app) @app = app @config = RailsAiContext.configuration end |
Instance Attribute Details
#app ⇒ Object (readonly)
Returns the value of attribute app.
7 8 9 |
# File 'lib/rails_ai_context/introspector.rb', line 7 def app @app end |
#config ⇒ Object (readonly)
Returns the value of attribute config.
7 8 9 |
# File 'lib/rails_ai_context/introspector.rb', line 7 def config @config end |
Instance Method Details
#call ⇒ Hash
Run all configured introspectors and return unified context hash
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/rails_ai_context/introspector.rb', line 17 def call context = { app_name: app_name, ruby_version: RUBY_VERSION, rails_version: Rails.version, environment: Rails.env, generated_at: Time.current.iso8601, generator: "rails-ai-context v#{RailsAiContext::VERSION}" } config.introspectors.each do |name| introspector = resolve_introspector(name) context[name] = introspector.call rescue => e context[name] = { error: e. } Rails.logger.warn "[rails-ai-context] #{name} introspection failed: #{e.}" end # Collect warnings for introspectors that failed, so serializers can # render them and AI clients know which sections are missing. warnings = [] config.introspectors.each do |name| data = context[name] if data.is_a?(Hash) && data[:error] warnings << { introspector: name.to_s, error: data[:error] } end end context[:_warnings] = warnings if warnings.any? context end |