Sha256: 7a31fefca9298a9ae53b9073cf3ac9e92c61e43859b1f5911f1737a8b650c9e2

Contents?: true

Size: 747 Bytes

Versions: 3

Compression:

Stored size: 747 Bytes

Contents

# frozen_string_literal: true

require 'progress'

module ActiveRecord
  # Add find_each_with_progress and find_in_batches_with_progress method to
  # ActiveRecord::Base
  class Base
    # run `find_each` with progress
    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

    # run `find_in_batches` with progress
    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
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
progress-3.6.0 lib/progress/active_record.rb
progress-3.5.2 lib/progress/active_record.rb
progress-3.5.1 lib/progress/active_record.rb