Sha256: 4fec7b9dcc671612366cb9126146cb32c4639b665f9ba3067bb6bde20670df76

Contents?: true

Size: 774 Bytes

Versions: 6

Compression:

Stored size: 774 Bytes

Contents

require 'progress'

if defined?(ActiveRecord::Base)
  module ActiveRecord
    module BatchesWithProgress
      # 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

    class Base
      extend BatchesWithProgress
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
progress-2.4.0 lib/progress/active_record.rb
progress-2.3.0 lib/progress/active_record.rb
progress-2.2.0 lib/progress/active_record.rb
progress-2.1.1 lib/progress/active_record.rb
progress-2.1.0 lib/progress/active_record.rb
progress-2.0.0 lib/progress/active_record.rb