Sha256: 28ef10e93028854c00fa1fc43167f4c58ae48531fc50b6db77cc94856d17a9cf
Contents?: true
Size: 1.36 KB
Versions: 1
Compression:
Stored size: 1.36 KB
Contents
# encoding: utf-8 module CarrierWave module Workers class StoreAsset < Struct.new(:klass, :id, :column) include ::Sidekiq::Worker if defined?(::Sidekiq) attr_reader :cache_path, :tmp_directory def self.perform(*args) new(*args).perform end def perform(*args) set_args(*args) if args.present? record = constantized_resource.find id if record.send(:"#{column}_tmp") store_directories(record) 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_directory, :force => true) end end end private def set_args(klass, id, column) self.klass, self.id, self.column = klass, id, column end def constantized_resource klass.is_a?(String) ? klass.constantize : klass end def store_directories(record) asset, asset_tmp = record.send(:"#{column}"), record.send(:"#{column}_tmp") cache_directory = File.join(asset.root, asset.cache_dir) @cache_path = File.join(cache_directory, asset_tmp) @tmp_directory = File.join(cache_directory, asset_tmp.split("/").first) end end # StoreAsset end # Workers end # Backgrounder
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
carrierwave_backgrounder-0.1.3 | lib/backgrounder/workers/store_asset.rb |