Class: RailsAiContext::Hydrators::ControllerHydrator
- Inherits:
-
Object
- Object
- RailsAiContext::Hydrators::ControllerHydrator
- Defined in:
- lib/rails_ai_context/hydrators/controller_hydrator.rb
Overview
Parses a controller source file via Prism AST, detects model references, and builds SchemaHint objects for each detected model.
Class Method Summary collapse
-
.call(source_path, context:) ⇒ Object
Hydrate a controller file with schema hints.
Class Method Details
.call(source_path, context:) ⇒ Object
Hydrate a controller file with schema hints. Returns a HydrationResult with hints for all detected models.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/rails_ai_context/hydrators/controller_hydrator.rb', line 10 def self.call(source_path, context:) return HydrationResult.new unless source_path && File.exist?(source_path) return HydrationResult.new if File.size(source_path) > RailsAiContext.configuration.max_file_size model_names = detect_model_references(source_path) return HydrationResult.new if model_names.empty? hints = SchemaHintBuilder.build_many(model_names, context: context, max: RailsAiContext.configuration.hydration_max_hints) warnings = [] unresolved = model_names - hints.map(&:model_name) unresolved.each do |name| warnings << "Model '#{name}' referenced but not found in introspection data" end HydrationResult.new(hints: hints, warnings: warnings) rescue => e $stderr.puts "[rails-ai-context] ControllerHydrator failed: #{e.}" if ENV["DEBUG"] HydrationResult.new end |