From 4b760d4725346c5bb5fcbe361a72d42c751a9e43 Mon Sep 17 00:00:00 2001 From: xiaohui Date: Sun, 21 Sep 2025 23:14:10 +0800 Subject: [PATCH] refactor: extract populate_messages method for customizable message loading --- lib/ruby_llm/active_record/chat_methods.rb | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/lib/ruby_llm/active_record/chat_methods.rb b/lib/ruby_llm/active_record/chat_methods.rb index 173f14bf6..c1d3a3fd1 100644 --- a/lib/ruby_llm/active_record/chat_methods.rb +++ b/lib/ruby_llm/active_record/chat_methods.rb @@ -73,6 +73,13 @@ def resolve_model_from_strings # rubocop:disable Metrics/PerceivedComplexity @provider_string = nil end + def populate_messages + @chat.reset_messages! + messages_association.each do |msg| + @chat.add_message(msg.to_llm) + end + end + public def to_llm @@ -81,12 +88,7 @@ def to_llm model: model_record.model_id, provider: model_record.provider.to_sym ) - @chat.reset_messages! - - messages_association.each do |msg| - @chat.add_message(msg.to_llm) - end - + populate_messages setup_persistence_callbacks end