Skip to content

Commit

Permalink
Merge pull request #157 from phlex-ruby/csv
Browse files Browse the repository at this point in the history
Add special Phlex::CSV handling for ActiveRecord::Relation collections
  • Loading branch information
joeldrapper authored Mar 16, 2024
2 parents 69c64f8 + a86a8e8 commit df5e20c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/phlex/rails.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ module Rails
end
end

class CSV
prepend Phlex::Rails::CSV::Overrides
end

class SGML
extend Phlex::Rails::SGML::ClassMethods

Expand Down
18 changes: 18 additions & 0 deletions lib/phlex/rails/csv/overrides.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# frozen_string_literal: true

module Phlex
module Rails
module CSV
module Overrides
def each_item(&block)
case collection
when ActiveRecord::Relation
collection.find_each(&block)
else
super
end
end
end
end
end
end

0 comments on commit df5e20c

Please sign in to comment.