Class: RailsAiBridge::Tools::GetContext::Composer

Inherits:
Object
  • Object
show all
Defined in:
lib/rails_ai_bridge/tools/get_context/composer.rb

Overview

Renders the composite markdown payload for RailsAiBridge::Tools::GetContext.

Constant Summary collapse

SUMMARY_ASSOC_LIMIT =

Max association, validation, route, and filter samples in summary output.

3
TEST_LIMITS =

Related-test path caps keyed by detail level.

{ 'summary' => 5, 'standard' => 10, 'full' => 20 }.freeze

Instance Method Summary collapse

Constructor Details

#initialize(resolution:, snapshots:, detail:, test_paths:) ⇒ Composer

Returns a new instance of Composer.

Parameters:

  • resolution (Hash)

    output of Resolver#call

  • snapshots (Hash{Symbol => Object})
  • detail (String)
  • test_paths (Array<String>)


17
18
19
20
21
22
# File 'lib/rails_ai_bridge/tools/get_context/composer.rb', line 17

def initialize(resolution:, snapshots:, detail:, test_paths:)
  @resolution = resolution
  @snapshots = snapshots
  @detail = %w[summary standard full].include?(detail) ? detail : 'summary'
  @test_paths = test_paths
end

Instance Method Details

#callString

Returns markdown body.

Returns:

  • (String)

    markdown body



25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/rails_ai_bridge/tools/get_context/composer.rb', line 25

def call
  return [@resolution[:error], *@resolution[:setup_messages]].compact.join("\n\n") if hard_error?

  lines = ["# Context: #{heading_label}", '']
  @resolution[:setup_messages].each { |message| lines << message << '' }
  append_table(lines)
  append_model(lines)
  append_routes(lines)
  append_controller(lines)
  append_tests(lines)
  lines.join("\n").strip
end