Class: ActiveRecord::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/progress/active_record.rb

Overview

Add find_each_with_progress and find_in_batches_with_progress method to ActiveRecord::Base

Instance Method Summary collapse

Instance Method Details

#find_each_with_progress(options = {}) ⇒ Object

run ‘find_each` with progress



10
11
12
13
14
15
16
17
18
# File 'lib/progress/active_record.rb', line 10

def find_each_with_progress(options = {})
  Progress.start(name.tableize, count(options)) do
    find_each do |model|
      Progress.step do
        yield model
      end
    end
  end
end

#find_in_batches_with_progress(options = {}) ⇒ Object

run ‘find_in_batches` with progress



21
22
23
24
25
26
27
28
29
# File 'lib/progress/active_record.rb', line 21

def find_in_batches_with_progress(options = {})
  Progress.start(name.tableize, count(options)) do
    find_in_batches do |batch|
      Progress.step batch.length do
        yield batch
      end
    end
  end
end