Summary
Move Rails-specific integration (lazy hooks and the render csv: renderer) out of lib/comma.rb into dedicated files under lib/comma/rails/.
Problem
lib/comma.rb currently mixes concerns:
- Gem boot and requires
ActiveSupport.on_load hooks for ActiveRecord, Mongoid, ActionController
- ~30 lines registering the
:csv renderer (filename, BOM, MIME type, option slicing, send_data)
This makes the entry point harder to read and means Rails integration cannot be tested or reviewed in isolation without scrolling through unrelated code.
Proposed approach
lib/comma.rb # thin loader only
lib/comma/rails.rb # on_load hooks, require integration files
lib/comma/rails/renderer.rb # ActionController::Renderers.add :csv
Keep the same lazy-loading behavior via ActiveSupport.on_load(:action_controller).
Optional follow-up (separate issue): require comma/rails only when Rails is present; today the hooks are in the main require path but no-op until frameworks load.
Files likely involved
lib/comma.rb (slim down)
- New:
lib/comma/rails.rb, lib/comma/rails/renderer.rb
spec/controllers/users_controller_spec.rb (integration regression)
spec/spec_helper.rb (load path unchanged for tests)
Acceptance criteria
Labels (suggested)
refactor
Depends on
Optional: #3 (options normalization) — renderer extraction is simpler if options parsing already lives in Comma::Options.
Summary
Move Rails-specific integration (lazy hooks and the
render csv:renderer) out oflib/comma.rbinto dedicated files underlib/comma/rails/.Problem
lib/comma.rbcurrently mixes concerns:ActiveSupport.on_loadhooks for ActiveRecord, Mongoid, ActionController:csvrenderer (filename, BOM, MIME type, option slicing,send_data)This makes the entry point harder to read and means Rails integration cannot be tested or reviewed in isolation without scrolling through unrelated code.
Proposed approach
Keep the same lazy-loading behavior via
ActiveSupport.on_load(:action_controller).Optional follow-up (separate issue): require
comma/railsonly when Rails is present; today the hooks are in the main require path but no-op until frameworks load.Files likely involved
lib/comma.rb(slim down)lib/comma/rails.rb,lib/comma/rails/renderer.rbspec/controllers/users_controller_spec.rb(integration regression)spec/spec_helper.rb(load path unchanged for tests)Acceptance criteria
require 'comma'behavior unchanged for non-Rails appsrender csv: User.allstill works in controller specswrite_headers, etc.) still pass controller specslib/comma.rbno longer contains renderer implementation detailsLabels (suggested)
refactorDepends on
Optional: #3 (options normalization) — renderer extraction is simpler if options parsing already lives in
Comma::Options.