Skip to content

Conversation

@trevorturk
Copy link
Contributor

Summary

  • Fixes Zeitwerk::NameError when eager loading without ActiveRecord present
  • Wraps all lib/ruby_llm/active_record/*.rb files with if defined?(ActiveRecord::Base) check
  • Adds active_record directory to Zeitwerk ignore list
  • Updates railtie to load method modules before acts_as modules

Details

This PR ensures all ActiveRecord integration files only define their modules when ActiveRecord is available, following the pattern for conditional module loading.

Changes:

  • Wrapped acts_as.rb, acts_as_legacy.rb, chat_methods.rb, message_methods.rb, and model_methods.rb with if defined?(ActiveRecord::Base)
  • Added loader.ignore("#{__dir__}/ruby_llm/active_record") to prevent Zeitwerk from auto-loading these conditional files
  • Updated railtie initializer to explicitly require method modules before acts_as modules
  • Removed duplicate require from lib/ruby_llm.rb (now only in railtie)

Testing:

  • ✅ Zeitwerk eager load works without ActiveRecord
  • ✅ Zeitwerk eager load works with ActiveRecord
  • ✅ All specs pass

🤖 Generated with Claude Code

Wrap all ActiveRecord module definitions with `if defined?(ActiveRecord::Base)`
to prevent Zeitwerk errors when ActiveRecord is not present.

- Wrap active_record/*.rb files with ActiveRecord::Base check
- Add active_record directory to Zeitwerk ignore list
- Load method modules before acts_as in railtie initializer
- Remove duplicate require of acts_as from lib/ruby_llm.rb

Fixes Zeitwerk::NameError when eager loading without ActiveRecord.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@trevorturk
Copy link
Contributor Author

This one is much easier to view with Hide Whitespace enabled: https://github.com/crmne/ruby_llm/pull/504/files?w=1

trevorturk added a commit to trevorturk/ruby_llm that referenced this pull request Nov 18, 2025
Adds validation that Zeitwerk can eager load all files without errors.
This catches autoloading issues like inflector bugs and missing
conditional checks before they reach production.

- Added check after linter step for fast fail
- Runs on all Ruby/Rails matrix combinations
- ~2 second check prevents production crashes

## Blocked

This PR depends on crmne#504 (ActiveRecord dependency fix) to pass.
Without it, the eager loading check fails with NameError.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
trevorturk added a commit to trevorturk/ruby_llm-mcp that referenced this pull request Nov 18, 2025
Adds a validation step that runs Zeitwerk::Loader.eager_load_all after
dependency installation to catch autoloading issues early in the CI pipeline.

This check helps prevent production crashes by detecting:
- Inflector configuration errors
- Constant definition issues
- Missing conditional checks for optional dependencies

The check runs quickly (~2 seconds) before the test matrix, providing
rapid feedback on structural issues.

Note: This check currently fails due to upstream ruby_llm ActiveRecord
dependency issues. See:
- crmne/ruby_llm#504
- crmne/ruby_llm#505

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant