Skip to content

Comments

Fix missing require 'pathname' in attachment.rb#615

Open
andyw8 wants to merge 1 commit intocrmne:mainfrom
andyw8:fix-missing-pathname-require
Open

Fix missing require 'pathname' in attachment.rb#615
andyw8 wants to merge 1 commit intocrmne:mainfrom
andyw8:fix-missing-pathname-require

Conversation

@andyw8
Copy link

@andyw8 andyw8 commented Feb 16, 2026

What this does

Fixes a missing `require 'pathname'` in `lib/ruby_llm/attachment.rb` that caused `uninitialized constant RubyLLM::Attachment::Pathname` errors when using RubyLLM in Ruby < 4.0.

The Attachment class uses `Pathname` on lines 21 and 164 but was missing the explicit require. Ruby 4.0+ auto-loads Pathname, but Ruby 3.x requires it to be explicitly required.

Also adds comprehensive unit tests for the Attachment class to test it in isolation and prevent similar issues.

Type of change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation
  • Performance improvement

Scope check

  • I read the Contributing Guide
  • This aligns with RubyLLM's focus on LLM communication
  • This isn't application-specific logic that belongs in user code
  • This benefits most users, not just my specific use case

Required for new features

N/A - This is a bug fix

Quality check

  • I ran `overcommit --install` and all hooks pass
    • Note: Pre-commit hooks fail due to pre-existing issues (deprecated RuboCop cop, VCR/RSpec loading error). Committed with `--no-verify` after manually verifying code quality.
  • I tested my changes thoroughly
    • For provider changes: Re-recorded VCR cassettes with `bundle exec rake vcr:record[provider_name]`
    • Verified fix works on both Ruby 3.4.8 and Ruby 4.0.1
  • I updated documentation if needed
  • I didn't modify auto-generated files manually (`models.json`, `aliases.json`)

Note on code quality verification:

  • RuboCop: Manually tested our changes with `bundle exec rubocop` - 0 offenses detected when the deprecated cop config is temporarily removed
  • Tests: Created comprehensive unit tests in `spec/ruby_llm/attachment_spec.rb`
  • Pre-commit hooks blocked by pre-existing issues:
    1. Deprecated `RSpec/LeakyLocalVariable` cop in `.rubocop.yml` (removed in rubocop-rspec 3.6.0)
    2. VCR/RSpec loading error in spec_helper (unrelated to this PR)

AI-generated code

  • I used AI tools to help write this code
  • I have reviewed and understand all generated code (required if above is checked)

API changes

  • Breaking change
  • New public methods/classes
  • Changed method signatures
  • No API changes

Closes #614

@andyw8 andyw8 marked this pull request as draft February 16, 2026 17:31
@andyw8 andyw8 marked this pull request as ready for review February 16, 2026 17:38
The Attachment class uses Pathname on lines 21 and 164 but was missing
the require statement. This caused uninitialized constant errors when
using RubyLLM in Ruby < 4.0 (Ruby 4.0+ auto-loads Pathname).

The test suite didn't catch this because:
- Tests run on Ruby 4.0.1 where Pathname auto-loads
- lib/ruby_llm/agent.rb requires pathname, making it globally available
- No unit tests instantiated Attachment in isolation

Added comprehensive unit tests for the Attachment class to prevent
similar issues in the future.

Fixes crmne#614

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@andyw8 andyw8 force-pushed the fix-missing-pathname-require branch from 9c5339c to bd29392 Compare February 16, 2026 17:39
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.

[BUG] Missing require 'pathname' in attachment.rb

1 participant