Module: ActiveRecord::OnDemand::Streaming::ClassMethods
- Defined in:
- lib/ar-ondemand/for_streaming.rb
Instance Method Summary collapse
Instance Method Details
#for_streaming(options = {}) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/ar-ondemand/for_streaming.rb', line 10 def for_streaming( = {}) [:batch_size] ||= 50_000 fr = .delete(:for_reading) # TODO Clean this up after dropping support for Rails 3 if ActiveRecord::VERSION::MAJOR == 3 s = self.respond_to?(:to_sql) ? self : self.scoped else s = self.respond_to?(:to_sql) ? self : self.all end ::Enumerator.new do |n| s.send(fr ? :for_reading : :find_in_batches, ) do |b| b.each { |r| n << r } end end end |