Class: RailsAiBridge::Introspectors::SchemaIntrospector

Inherits:
Object
  • Object
show all
Defined in:
lib/rails_ai_bridge/introspectors/schema_introspector.rb

Overview

Extracts database schema information — tables, columns, indexes, and foreign keys — from a live ActiveRecord connection when available, or by text-parsing the schema file when no connection is present (CI, Claude Code, offline environments). The static fallback prefers db/schema.rb (RailsAiBridge::Introspectors::Schema::StaticSchemaParser) and falls back to db/structure.sql (RailsAiBridge::Introspectors::Schema::StaticStructureSqlParser) for schema_format = :sql apps.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ SchemaIntrospector

Returns a new instance of SchemaIntrospector.

Parameters:

  • app (Rails::Application)


22
23
24
25
# File 'lib/rails_ai_bridge/introspectors/schema_introspector.rb', line 22

def initialize(app)
  @app    = app
  @config = RailsAiBridge.configuration
end

Instance Attribute Details

#appRails::Application (readonly)

Returns:

  • (Rails::Application)


16
17
18
# File 'lib/rails_ai_bridge/introspectors/schema_introspector.rb', line 16

def app
  @app
end

#configRailsAiBridge::Configuration (readonly)



19
20
21
# File 'lib/rails_ai_bridge/introspectors/schema_introspector.rb', line 19

def config
  @config
end

Instance Method Details

#callHash{Symbol => Object}

Returns database schema context. Uses a live connection when available; falls back to static text-parsing otherwise.

Returns:

  • (Hash{Symbol => Object})

    includes :adapter, :tables, :total_tables, and :schema_version (live) or :note (static)



32
33
34
35
36
37
38
39
40
41
# File 'lib/rails_ai_bridge/introspectors/schema_introspector.rb', line 32

def call
  return static_schema_parse unless active_record_connected?

  {
    adapter: adapter_name,
    tables: extract_tables,
    total_tables: table_names.size,
    schema_version: current_schema_version
  }
end