Sha256: fe1012e358d806877586a298883ecfbbc65c76183b8b30b48fdf6db55ed750a6

Contents?: true

Size: 904 Bytes

Versions: 4

Compression:

Stored size: 904 Bytes

Contents

# frozen_string_literal: true

# t.string :attr_name, null: false
# t.string :deleted_ids, default: ''
# t.boolean :clean_before, default: false
# t.text :files

module ActivestorageDelayed
  class DelayedUpload < ActiveRecord::Base
    self.table_name = 'activestorage_delayed_uploads'
    attr_accessor :tmp_files

    belongs_to :uploadable, polymorphic: true

    before_save :parse_tmp_files
    after_create_commit do
      ActivestorageDelayed::DelayedUploaderJob.perform_later(id)
    end

    private

    def parse_tmp_files
      self.files = (tmp_files.is_a?(Array) ? tmp_files : [tmp_files]).select(&:present?).map do |file|
        {
          'io' => Base64.encode64(file.read),
          'filename' => file.try(:original_filename) || File.basename(file.path),
          'content_type' => file.try(:content_type) || Marcel::MimeType.for(file)
        }
      end.to_json
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
activestorage-delayed-0.1.3 lib/activestorage-delayed/models/delayed_upload.rb
activestorage-delayed-0.1.2 lib/activestorage-delayed/models/delayed_upload.rb
activestorage-delayed-0.1.1 lib/activestorage-delayed/models/delayed_upload.rb
activestorage-delayed-0.1.0 lib/activestorage-delayed/models/delayed_upload.rb