Sha256: 97ad3eac0ddc9ca3647035b980cc0bbbece1ee978ede2fbe70a315fb64caa1cf

Contents?: true

Size: 1.08 KB

Versions: 9

Compression:

Stored size: 1.08 KB

Contents

# frozen_string_literal: true

module Archangel
  ##
  # Asset uploader
  #
  class AssetUploader < ApplicationUploader
    version :small, if: :image_format? do
      process resize_to_fit: [64, 64]
    end

    version :tiny, from_version: :small, if: :image_format? do
      process resize_to_fit: [32, 32]
    end

    ##
    # File extension whitelist
    #
    # @return [Array] file extension whitelist
    #
    def extension_whitelist
      Archangel.config.asset_extension_whitelist
    end

    ##
    # Uploaded path for file
    #
    # @return [String] upload path
    #
    def default_path
      "archangel/fallback/" + [version_name, "asset.png"].compact.join("_")
    end

    ##
    # Uploaded file name
    #
    # @return [String] randomly generated file name
    #
    def filename
      "#{secure_token}.#{file.extension}" if original_filename.present?
    end

    protected

    def secure_token
      secure_var = :"@#{mounted_as}_secure_token"

      model.instance_variable_get(secure_var) ||
        model.instance_variable_set(secure_var, SecureRandom.uuid)
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
archangel-0.4.0 app/uploaders/archangel/asset_uploader.rb
archangel-0.3.0 app/uploaders/archangel/asset_uploader.rb
archangel-0.0.8 app/uploaders/archangel/asset_uploader.rb
archangel-0.0.7 app/uploaders/archangel/asset_uploader.rb
archangel-0.0.6 app/uploaders/archangel/asset_uploader.rb
archangel-0.0.5 app/uploaders/archangel/asset_uploader.rb
archangel-0.0.4 app/uploaders/archangel/asset_uploader.rb
archangel-0.0.3 app/uploaders/archangel/asset_uploader.rb
archangel-0.0.2 app/uploaders/archangel/asset_uploader.rb