Skip to content

Unify collection #to_comma extensions - #179

Merged
eitoball merged 1 commit into
masterfrom
eitoball/unify-collection-to_comma-extensions
Sep 5, 2026
Merged

Unify collection #to_comma extensions#179
eitoball merged 1 commit into
masterfrom
eitoball/unify-collection-to_comma-extensions

Conversation

@eitoball

@eitoball eitoball commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

What

Replace the duplicated #to_comma one-liner on Array, Mongoid::Criteria, and DataMapper::Collection with a shared Comma::CollectionExport module.

Why

Three files implemented the exact same method body. Extracting it into one module removes the duplication without touching ActiveRecord::Relation, which has genuinely different logic (:find_each vs :each selection based on limit/order, plus a warning log) and stays separate.

Fixes #165

Changes

  • Add lib/comma/collection_export.rb with Comma::CollectionExport#to_comma
  • lib/comma/array.rb, lib/comma/mongoid.rb, lib/comma/data_mapper_collection.rb now include Comma::CollectionExport instead of defining their own to_comma
  • Reorder requires in lib/comma.rb so collection_export loads before data_mapper_collection (which includes it eagerly at load time)
  • Add lib/comma/collection_export.rb to the Style/Documentation exclude list in .rubocop_todo.yml, matching the existing convention for this project's lib files

No public API change; ActiveRecord::Relation#to_comma is unaffected.

Test plan

  • bundle exec rspec — 57 examples, 0 failures
  • bundle exec rubocop — no offenses
  • Note: spec/comma/rails/mongoid_spec.rb and spec/comma/rails/data_mapper_collection_spec.rb are pre-existing and gated behind if defined? Mongoid/DataMapper; neither gem is a dependency anywhere in this project, so these specs don't execute here or in CI (unrelated to this change)

🤖 Generated with Claude Code

Array, Mongoid::Criteria, and DataMapper::Collection each defined an
identical one-liner #to_comma. Extract it into Comma::CollectionExport
and include it in all three, removing the duplication.
ActiveRecord::Relation keeps its own implementation since it selects
:find_each vs :each based on limit/order and logs a warning.

Fixes #165

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Copilot AI lite review requested due to automatic review settings September 5, 2026 11:56

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The refactor cleanly removes duplication while preserving the existing to_comma behavior and ensures load order correctness via updated requires.

Pull request overview

This PR removes duplicated #to_comma implementations across non-ActiveRecord collection integrations by extracting the shared one-liner into a single Comma::CollectionExport module, keeping ActiveRecord::Relation#to_comma untouched due to its special iterator-selection behavior.

Changes:

  • Introduces Comma::CollectionExport#to_comma as the shared implementation.
  • Updates Array, Mongoid::Criteria, and DataMapper::Collection extensions to include Comma::CollectionExport instead of redefining to_comma.
  • Adjusts lib/comma.rb require ordering so collection_export loads before extensions that include it, and updates RuboCop todo excludes accordingly.
File summaries
File Description
lib/comma/collection_export.rb Adds shared to_comma implementation for collection-like types.
lib/comma/array.rb Replaces inline to_comma with include Comma::CollectionExport.
lib/comma/mongoid.rb Replaces inline to_comma with include Comma::CollectionExport for Mongoid criteria.
lib/comma/data_mapper_collection.rb Replaces inline to_comma with include Comma::CollectionExport for DataMapper collections.
lib/comma.rb Requires collection_export before extensions that depend on it.
.rubocop_todo.yml Excludes new lib file from Style/Documentation to match existing project pattern.
Review details
  • Files reviewed: 6/6 changed files
  • Comments generated: 0
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@eitoball
eitoball merged commit b0632d4 into master Sep 5, 2026
73 checks passed
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.

Unify collection #to_comma extensions

2 participants