Sha256: 9354e5d699416208ddb9a63097f10f3dc10a9e633778c07cfc9a2c5cfca2d1d5

Contents?: true

Size: 876 Bytes

Versions: 1

Compression:

Stored size: 876 Bytes

Contents

require "active_storage/blob"
require "active_storage/attachment"

require "action_dispatch/http/upload"
require "active_support/core_ext/module/delegation"

class ActiveStorage::Attached
  attr_reader :name, :record

  def initialize(name, record)
    @name, @record = name, record
  end

  private
    def create_blob_from(attachable)
      case attachable
      when ActiveStorage::Blob
        attachable
      when ActionDispatch::Http::UploadedFile
        ActiveStorage::Blob.create_after_upload! \
          io: attachable.open,
          filename: attachable.original_filename,
          content_type: attachable.content_type
      when Hash
        ActiveStorage::Blob.create_after_upload!(attachable)
      else
        nil
      end
    end
end

require "active_storage/attached/one"
require "active_storage/attached/many"
require "active_storage/attached/macros"

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
activestorage-0.1 lib/active_storage/attached.rb