Sha256: 7833ad8f75740569488613551e8475a5fe557236d2de040b6f2a1f9725db0099

Contents?: true

Size: 888 Bytes

Versions: 9

Compression:

Stored size: 888 Bytes

Contents

require 'ruby-progressbar'

namespace :assets do
  # rake assets:reprocess CLASS=PostImage
  desc 'Refresh carrierwave assets versions by model (CLASS=)'
  task reprocess: :environment do
    name = (ENV['CLASS'] || ENV['class'] || 'Asset').to_s
    klass = name.safe_constantize

    if ENV['VERSIONS']
      versions = ENV['VERSIONS'].split(',').map(&:to_sym)
    else
      versions = []
    end

    raise "Cannot find a constant with the #{name} specified in the argument string" if klass.nil?

    bar = ProgressBar.create(title: name, total: klass.count, format: '%c of %C - %a %e |%b>>%i| %p%% %t')
    bar.progress_mark = '='

    klass.find_each do |item|
      begin
        item.data.recreate_versions!(*versions)
        bar.increment
      rescue => e
        puts "ERROR recreate_versions for #{name} - #{item.id}: #{e.message}"
      end
    end

    bar.finish
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
ab_admin-0.9.0 lib/tasks/assets.rake
ab_admin-0.8.3 lib/tasks/assets.rake
ab_admin-0.8.2 lib/tasks/assets.rake
ab_admin-0.8.1 lib/tasks/assets.rake
ab_admin-0.8.0 lib/tasks/assets.rake
ab_admin-0.7.0 lib/tasks/assets.rake
ab_admin-0.6.1 lib/tasks/assets.rake
ab_admin-0.6.0 lib/tasks/assets.rake
ab_admin-0.5.0 lib/tasks/assets.rake