Skip to content

Commit aa73ba7

Browse files
committed
Fix ActiveRecord eager-load isolation
1 parent 776d92a commit aa73ba7

11 files changed

Lines changed: 33 additions & 4 deletions

File tree

.github/workflows/_test-matrix.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ jobs:
5252
bundle install
5353
bundle exec appraisal ${{ matrix.rails-version }} bundle install
5454
55+
- name: Run eager-load guard (appraisal)
56+
run: bundle exec appraisal ${{ matrix.rails-version }} ruby -e "require 'ruby_llm'; Zeitwerk::Loader.eager_load_all"
57+
5558
- name: Run tests
5659
if: matrix.ruby-version != '4.0' || matrix.rails-version != 'rails-8.1'
5760
run: bundle exec appraisal ${{ matrix.rails-version }} bin/rspec-queue

lib/ruby_llm.rb

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
)
3434
loader.ignore("#{__dir__}/tasks")
3535
loader.ignore("#{__dir__}/generators")
36+
loader.ignore("#{__dir__}/ruby_llm/active_record")
3637
loader.ignore("#{__dir__}/ruby_llm/railtie.rb")
3738
loader.setup
3839

@@ -107,7 +108,4 @@ def logger
107108
RubyLLM::Provider.register :vertexai, RubyLLM::Providers::VertexAI
108109
RubyLLM::Provider.register :xai, RubyLLM::Providers::XAI
109110

110-
if defined?(Rails::Railtie)
111-
require 'ruby_llm/railtie'
112-
require 'ruby_llm/active_record/acts_as'
113-
end
111+
require 'ruby_llm/railtie' if defined?(Rails::Railtie)

lib/ruby_llm/active_record/acts_as.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# frozen_string_literal: true
22

3+
require 'active_support/concern'
4+
require 'active_support/inflector'
5+
36
module RubyLLM
47
module ActiveRecord
58
# Adds chat and message persistence capabilities to ActiveRecord models.

lib/ruby_llm/active_record/acts_as_legacy.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# frozen_string_literal: true
22

3+
require 'active_support/concern'
4+
require 'active_support/inflector'
5+
36
module RubyLLM
47
module ActiveRecord
58
# Adds chat and message persistence capabilities to ActiveRecord models.

lib/ruby_llm/active_record/chat_methods.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# frozen_string_literal: true
22

3+
require 'active_support/concern'
4+
35
module RubyLLM
46
module ActiveRecord
57
# Methods mixed into chat models.

lib/ruby_llm/active_record/message_methods.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# frozen_string_literal: true
22

3+
require 'active_support/concern'
4+
require 'ruby_llm/active_record/payload_helpers'
5+
36
module RubyLLM
47
module ActiveRecord
58
# Methods mixed into message models.

lib/ruby_llm/active_record/model_methods.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# frozen_string_literal: true
22

3+
require 'active_support/concern'
4+
require 'active_support/core_ext/module/delegation'
5+
36
module RubyLLM
47
module ActiveRecord
58
# Methods mixed into model registry models.

lib/ruby_llm/active_record/payload_helpers.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# frozen_string_literal: true
22

3+
require 'active_support/core_ext/object/blank'
4+
require 'json'
5+
36
module RubyLLM
47
module ActiveRecord
58
# Shared helpers for parsing serialized payloads on ActiveRecord-backed models.

lib/ruby_llm/active_record/tool_call_methods.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# frozen_string_literal: true
22

3+
require 'active_support/concern'
4+
require 'ruby_llm/active_record/payload_helpers'
5+
36
module RubyLLM
47
module ActiveRecord
58
# Methods mixed into tool call models.

lib/ruby_llm/railtie.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ class Railtie < Rails::Railtie
1212

1313
initializer 'ruby_llm.active_record' do
1414
ActiveSupport.on_load :active_record do
15+
require 'ruby_llm/active_record/payload_helpers'
16+
require 'ruby_llm/active_record/chat_methods'
17+
require 'ruby_llm/active_record/message_methods'
18+
require 'ruby_llm/active_record/model_methods'
19+
require 'ruby_llm/active_record/tool_call_methods'
20+
1521
if RubyLLM.config.use_new_acts_as
1622
require 'ruby_llm/active_record/acts_as'
1723
::ActiveRecord::Base.include RubyLLM::ActiveRecord::ActsAs

0 commit comments

Comments
 (0)