Class: RailsAiBridge::Tools::Schema::SummaryFormatter

Inherits:
Object
  • Object
show all
Defined in:
lib/rails_ai_bridge/tools/schema/summary_formatter.rb

Overview

Renders a compact summary of all tables: name + column/index counts.

Instance Method Summary collapse

Constructor Details

#initialize(tables:, total:, limit:, offset:, source: nil) ⇒ void

Parameters:

  • tables (Hash{String => Hash})

    table name => introspection payload

  • total (Integer)

    total number of tables in the schema

  • limit (Integer)

    max tables to display

  • offset (Integer)

    number of tables to skip

  • source (Symbol, String, nil) (defaults to: nil)

    :live (verified) or :static (inferred)



15
16
17
18
19
20
21
# File 'lib/rails_ai_bridge/tools/schema/summary_formatter.rb', line 15

def initialize(tables:, total:, limit:, offset:, source: nil)
  @tables = tables
  @total  = total
  @limit  = limit
  @offset = offset
  @source = source
end

Instance Method Details

#callString

Returns Markdown summary listing.

Returns:

  • (String)

    Markdown summary listing



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/rails_ai_bridge/tools/schema/summary_formatter.rb', line 24

def call
  paginated = @tables.keys.sort.drop(@offset).first(@limit)
  lines = ["# Schema Summary (#{@total} tables)", '']

  paginated.each do |name|
    data = @tables[name]
    col_count = data[:columns]&.size || 0
    idx_count = data[:indexes]&.size || 0
    lines << "- **#{name}** #{ConfidenceTag.tag(@source)}#{col_count} columns, #{idx_count} indexes"
  end

  if @offset + @limit < @total
    lines << '' << "_Showing #{paginated.size} of #{@total}. " \
                   "Use `offset:#{@offset + @limit}` for more, or `table:\"name\"` for full detail._"
  end

  lines.join("\n")
end