Class: RailsAiBridge::Tools::Schema::FullFormatter

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

Overview

Renders full table detail (columns, indexes, foreign keys) for a page of tables.

Instance Method Summary collapse

Constructor Details

#initialize(tables:, total:, limit:, offset:) ⇒ 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



14
15
16
17
18
19
# File 'lib/rails_ai_bridge/tools/schema/full_formatter.rb', line 14

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

Instance Method Details

#callString

Returns Markdown full-detail listing.

Returns:

  • (String)

    Markdown full-detail listing



22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/rails_ai_bridge/tools/schema/full_formatter.rb', line 22

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

  paginated.each do |name|
    lines << TableFormatter.new(name: name, data: @tables[name]).call
    lines << ''
  end

  lines << "_Showing #{paginated.size} of #{@total}. Use `offset:#{@offset + @limit}` for more._" if @offset + @limit < @total

  lines.join("\n")
end