Sha256: 601da8f22248d2c917b3b1f00ad9bf225eef7a6b0cb91992d43ba50c5f5bd6f2

Contents?: true

Size: 945 Bytes

Versions: 2

Compression:

Stored size: 945 Bytes

Contents

# encoding: utf-8
module CarrierWave
  module Workers

    class StoreAsset < Struct.new(:klass, :id, :column)
      @queue = :store_asset

      def self.perform(*args)
        new(*args).perform
      end

      def perform
        resource = klass.is_a?(String) ? klass.constantize : klass
        record = resource.find id
        if tmp = record.send(:"#{column}_tmp")
          asset = record.send(:"#{column}")
          cache_dir  = [asset.root, asset.cache_dir].join("/")
          cache_path = [cache_dir, tmp].join("/")
          tmp_dir = [cache_dir, tmp.split("/")[0]].join("/")
          record.send :"process_#{column}_upload=", true
          record.send :"#{column}_tmp=", nil
          File.open(cache_path) { |f| record.send :"#{column}=", f }
          if record.save!
            FileUtils.rm_r(tmp_dir, :force => true)
          end
        end
      end
      
    end # StoreAsset
    
  end # Workers
end # Backgrounder

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
carrierwave_backgrounder-0.0.7 lib/backgrounder/workers/store_asset.rb
carrierwave_backgrounder-0.0.6 lib/backgrounder/workers/store_asset.rb