Sha256: 83f26a4b7d5825db6b8575b1e638a023e47f787bcf1de245025ad579846b4987

Contents?: true

Size: 714 Bytes

Versions: 1

Compression:

Stored size: 714 Bytes

Contents

# encoding: utf-8
module CarrierWave
  module Workers

    class StoreAsset < Struct.new(:klass, :id, :column)
  
      def perform
        record = klass.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("/")
        
          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(cache_path)
          end
        end
      end
      
    end # StoreAsset
    
  end # Workers
end # Backgrounder

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
carrierwave_backgrounder-0.0.5 lib/backgrounder/workers/store_asset.rb