Sha256: 65696d65cb63fec656c797ae0e4d8b4b61fb1c31d3861be52f47b63dad6ff3f8

Contents?: true

Size: 727 Bytes

Versions: 6

Compression:

Stored size: 727 Bytes

Contents

namespace :db_memoize do
  desc "generates memoized values (pass e.g. 'class=Product methods=to_document,to_hash')"
  task warmup: :environment do
    require 'ruby-progressbar'

    klass_name = ENV['class']
    methods    = ENV['methods'].split(',')
    klass      = klass_name.constantize
    count      = klass.count

    progressbar = ProgressBar.create(
      title: "db_memoize warmup run for #{klass_name}",
      starting_at: 0,
      total: count,
      format: "%t [#{count}] |%bá—§%i| %p%% %e",
      progress_mark: ' ',
      remainder_mark: '.'
    )

    klass_name.constantize.find_each do |record|
      methods.each do |meth|
        record.send(meth)
      end

      progressbar.increment
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
db_memoize-0.1.5 lib/tasks/warmup.rake
db_memoize-0.1.4 lib/tasks/warmup.rake
db_memoize-0.1.3 lib/tasks/warmup.rake
db_memoize-0.1.2 lib/tasks/warmup.rake
db_memoize-0.1.1 lib/tasks/warmup.rake
db_memoize-0.1.0 lib/tasks/warmup.rake