Summary
Replace duplicated #to_comma implementations on Array, Mongoid::Criteria, and DataMapper::Collection with a shared module.
Problem
Three files implement the same one-liner pattern:
def to_comma(style = :default)
Comma::Generator.new(self, style).run(:each)
end
Locations:
lib/comma/array.rb
lib/comma/mongoid.rb
lib/comma/data_mapper_collection.rb
ActiveRecord::Relation (lib/comma/relation.rb) is different — it chooses :find_each vs :each based on limit/order and logs a warning. That logic should stay separate.
Proposed approach
# lib/comma/collection_export.rb
module Comma
module CollectionExport
def to_comma(style = :default, iterator: :each)
Comma::Generator.new(self, style).run(iterator)
end
end
end
Then:
class Array
include Comma::CollectionExport
end
Same for Mongoid and DataMapper hooks.
Files likely involved
- New:
lib/comma/collection_export.rb
lib/comma/array.rb
lib/comma/mongoid.rb
lib/comma/data_mapper_collection.rb
lib/comma.rb (require new file)
- Existing collection specs (comma_spec, mongoid_spec, data_mapper_collection_spec)
Acceptance criteria
Labels (suggested)
refactor, good first issue
Depends on
None.
Summary
Replace duplicated
#to_commaimplementations onArray,Mongoid::Criteria, andDataMapper::Collectionwith a shared module.Problem
Three files implement the same one-liner pattern:
Locations:
lib/comma/array.rblib/comma/mongoid.rblib/comma/data_mapper_collection.rbActiveRecord::Relation(lib/comma/relation.rb) is different — it chooses:find_eachvs:eachbased on limit/order and logs a warning. That logic should stay separate.Proposed approach
Then:
Same for Mongoid and DataMapper hooks.
Files likely involved
lib/comma/collection_export.rblib/comma/array.rblib/comma/mongoid.rblib/comma/data_mapper_collection.rblib/comma.rb(require new file)Acceptance criteria
Array#to_comma, Mongoid criteria, and DataMapper collection behavior unchangedActiveRecord::Relation#to_commaunchanged (still uses custom iterator)#to_commabodies removed from three filesLabels (suggested)
refactor,good first issueDepends on
None.