Sha256: f18e7ed9ab99a0ce5ebefaa5d7a905ba511a057476590e050add6be3546cd29e

Contents?: true

Size: 887 Bytes

Versions: 4

Compression:

Stored size: 887 Bytes

Contents

# encoding: utf-8
module CarrierWave
  module Workers

    module ProcessAssetMixin
      include CarrierWave::Workers::Base

      def self.included(base)
        base.extend CarrierWave::Workers::ClassMethods
      end

      def perform(*args)
        record = super(*args)
        asset = record.send(:"#{column}")

        return unless record && asset_present?(asset)

        recreate_asset_versions!(asset)

        if record.respond_to?(:"#{column}_processing")
          record.update_attribute :"#{column}_processing", false
        end
      end

      private

      def recreate_asset_versions!(asset)
        asset.is_a?(Array) ? asset.map(&:recreate_versions!) : asset.recreate_versions!
      end

      def asset_present?(asset)
        asset.is_a?(Array) ? asset.present? : asset.file.present?
      end
    end # ProcessAssetMixin

  end # Workers
end # Backgrounder

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
carrierwave_backgrounder-1.0.1 lib/backgrounder/workers/process_asset_mixin.rb
carrierwave_backgrounder-1.0.0 lib/backgrounder/workers/process_asset_mixin.rb
carrierwave_backgrounder-1.0.0.beta.2 lib/backgrounder/workers/process_asset_mixin.rb
carrierwave_backgrounder-1.0.0.beta lib/backgrounder/workers/process_asset_mixin.rb