Skip to content

Commit a86a8e8

Browse files
committed
Add special Phlex::CSV handling for ActiveRecord::Relation collections
1 parent 69c64f8 commit a86a8e8

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

lib/phlex/rails.rb

+4
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ module Rails
1717
end
1818
end
1919

20+
class CSV
21+
prepend Phlex::Rails::CSV::Overrides
22+
end
23+
2024
class SGML
2125
extend Phlex::Rails::SGML::ClassMethods
2226

lib/phlex/rails/csv/overrides.rb

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# frozen_string_literal: true
2+
3+
module Phlex
4+
module Rails
5+
module CSV
6+
module Overrides
7+
def each_item(&block)
8+
case collection
9+
when ActiveRecord::Relation
10+
collection.find_each(&block)
11+
else
12+
super
13+
end
14+
end
15+
end
16+
end
17+
end
18+
end

0 commit comments

Comments
 (0)