11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
# File 'lib/sage/model_scopes_context.rb', line 11
def build_context
context_parts = []
context_parts << "\n\n## AVAILABLE SCOPES → SQL MAPPINGS\n"
context_parts << "CRITICAL: Use these scopes to understand how to query the data!"
context_parts << "Each scope name shows the SQL conditions it generates."
context_parts << "When a user's request matches a scope's intent, use that scope's SQL pattern.\n"
begin
Rails.application.eager_load! if Rails.env.development?
rescue Zeitwerk::NameError => e
Rails.logger.warn "Could not eager load all files: #{e.message}"
end
models_with_scopes = collect_models_with_scopes
if models_with_scopes.any?
models_with_scopes.each do |model_info|
context_parts << "\n### #{model_info[:name]} (table: `#{model_info[:table]}`)"
context_parts << "Scopes and their SQL equivalents:"
model_info[:scopes].each do |scope|
context_parts << scope
end
end
end
context_parts.join("\n")
end
|