Sha256: 690ac5aaa446a8863b209699df232776efd1b29f9146b4776fef864d63bad887

Contents?: true

Size: 813 Bytes

Versions: 4

Compression:

Stored size: 813 Bytes

Contents

class ::FileUploader < Shrine
  plugin :versions
  plugin :processing

  process(:store) do |io, context|
    result = {}
    if context[:record].media_type == 'image'
      result = Cas::RemoteCallbacks.callbacks[:uploaded_image_versions].call(io, context)
    end
    original = (io.respond_to?(:[]) && io[:original]) ? io[:original] : io
    result = result.merge(original: original) unless result.keys.include?(:original)
    result
  end

  def generate_location(io, context)
    Rails.logger.info "FileUploader#generate_location"
    year  = Time.now.strftime("%Y")
    month = Time.now.strftime("%m")
    original_filename = context[:metadata]["filename"]

    # the default unique identifier
    name = "#{SecureRandom.hex[0..6]}-#{original_filename}"

    [year, month, name].compact.join("/")
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
cas-cms-0.1.3 app/uploaders/file_uploader.rb
cas-cms-0.1.2 app/uploaders/file_uploader.rb
cas-cms-0.1.1 app/uploaders/file_uploader.rb
cas-cms-0.1.0 app/uploaders/file_uploader.rb