Class: RailsAiBridge::Doctor

Inherits:
Object
  • Object
show all
Defined in:
lib/rails_ai_bridge/doctor.rb,
lib/rails_ai_bridge/doctor/check.rb,
lib/rails_ai_bridge/doctor/checkers/base_checker.rb,
lib/rails_ai_bridge/doctor/checkers/gems_checker.rb,
lib/rails_ai_bridge/doctor/checkers/i18n_checker.rb,
lib/rails_ai_bridge/doctor/checkers/tests_checker.rb,
lib/rails_ai_bridge/doctor/checkers/views_checker.rb,
lib/rails_ai_bridge/doctor/checkers/models_checker.rb,
lib/rails_ai_bridge/doctor/checkers/routes_checker.rb,
lib/rails_ai_bridge/doctor/checkers/schema_checker.rb,
lib/rails_ai_bridge/doctor/checkers/ripgrep_checker.rb,
lib/rails_ai_bridge/doctor/checkers/registry_checker.rb,
lib/rails_ai_bridge/doctor/checkers/migrations_checker.rb,
lib/rails_ai_bridge/doctor/checkers/controllers_checker.rb,
lib/rails_ai_bridge/doctor/checkers/context_files_checker.rb,
lib/rails_ai_bridge/doctor/checkers/mcp_buildable_checker.rb,
lib/rails_ai_bridge/doctor/checkers/view_mcp_tool_checker.rb,
lib/rails_ai_bridge/doctor/checkers/bridge_metadata_checker.rb,
lib/rails_ai_bridge/doctor/checkers/bridge_freshness_checker.rb,
lib/rails_ai_bridge/doctor/checkers/stimulus_mcp_tool_checker.rb

Overview

Diagnostic checker that validates the environment and reports AI readiness with pass/warn/fail checks and a readiness score.

Defined Under Namespace

Modules: Checkers Classes: Check

Constant Summary collapse

CHECKS =

Maps stable check identifiers to checker classes. Each value must implement .call on an instance and return a Check.

{
  check_schema: Checkers::SchemaChecker,
  check_models: Checkers::ModelsChecker,
  check_routes: Checkers::RoutesChecker,
  check_gems: Checkers::GemsChecker,
  check_controllers: Checkers::ControllersChecker,
  check_views: Checkers::ViewsChecker,
  check_i18n: Checkers::I18nChecker,
  check_tests: Checkers::TestsChecker,
  check_migrations: Checkers::MigrationsChecker,
  check_context_files: Checkers::ContextFilesChecker,
  check_bridge_freshness: Checkers::BridgeFreshnessChecker,
  check_mcp_buildable: Checkers::McpBuildableChecker,
  check_ripgrep: Checkers::RipgrepChecker,
  check_view_mcp_tool: Checkers::ViewMcpToolChecker,
  check_stimulus_mcp_tool: Checkers::StimulusMcpToolChecker,
  check_bridge_metadata: Checkers::BridgeMetadataChecker,
  check_registry: Checkers::RegistryChecker
}.freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app = nil, boot_result: nil, network: false) ⇒ void

Parameters:

  • app (Rails::Application, nil) (defaults to: nil)

    application to inspect

  • boot_result (Hash, nil) (defaults to: nil)

    structured result from BootManager.boot

  • network (Boolean) (defaults to: false)

    when true, enable network reachability checks



56
57
58
59
60
# File 'lib/rails_ai_bridge/doctor.rb', line 56

def initialize(app = nil, boot_result: nil, network: false)
  @app = app || AppScope.current_app
  @boot_result = boot_result
  @network = network
end

Instance Attribute Details

#appObject (readonly)

Returns the value of attribute app.



38
39
40
# File 'lib/rails_ai_bridge/doctor.rb', line 38

def app
  @app
end

#boot_resultObject (readonly)

Returns the value of attribute boot_result.



38
39
40
# File 'lib/rails_ai_bridge/doctor.rb', line 38

def boot_result
  @boot_result
end

#networkObject (readonly)

Returns the value of attribute network.



38
39
40
# File 'lib/rails_ai_bridge/doctor.rb', line 38

def network
  @network
end

Class Method Details

.run_for(root, timeout: BootManager::DEFAULT_TIMEOUT, network: false) ⇒ Hash

Boots an application and runs diagnostics, using static fallback on failure.

Parameters:

  • root (String, Pathname)

    application root

  • timeout (Numeric) (defaults to: BootManager::DEFAULT_TIMEOUT)

    maximum boot duration in seconds

  • network (Boolean) (defaults to: false)

    when true, enable network reachability checks

Returns:

  • (Hash)

    diagnostic result with :checks and :score



46
47
48
49
50
# File 'lib/rails_ai_bridge/doctor.rb', line 46

def self.run_for(root, timeout: BootManager::DEFAULT_TIMEOUT, network: false)
  boot_result = BootManager.boot(root, timeout: timeout)
  app = boot_result[:success] ? boot_result[:app] : BootManager.static_fallback(root)
  new(app, boot_result: boot_result, network: network).run
end

Instance Method Details

#runHash

Runs all diagnostic checks and computes a readiness score.

Returns:

  • (Hash)

    diagnostic result with :checks and :score



65
66
67
68
69
70
# File 'lib/rails_ai_bridge/doctor.rb', line 65

def run
  results = CHECKS.map { |name, checker_class| run_check(name, checker_class) }
  results.unshift(boot_failure_check) if boot_failed?
  score = compute_score(results)
  { checks: results, score: score }
end