Sha256: d7ef893139f4444c5326bf2939f88af903f26c03094e23765fdd226af63313a2

Contents?: true

Size: 696 Bytes

Versions: 41

Compression:

Stored size: 696 Bytes

Contents

# frozen_string_literal: true

module ActiveStorage::Blob::Identifiable
  def identify
    unless identified?
      update! content_type: identify_content_type, identified: true
      update_service_metadata
    end
  end

  def identified?
    identified
  end

  private
    def identify_content_type
      Marcel::MimeType.for download_identifiable_chunk, name: filename.to_s, declared_type: content_type
    end

    def download_identifiable_chunk
      if byte_size.positive?
        service.download_chunk key, 0...4.kilobytes
      else
        ""
      end
    end

    def update_service_metadata
      service.update_metadata key, service_metadata if service_metadata.any?
    end
end

Version data entries

41 entries across 41 versions & 5 rubygems

Version Path
activestorage-5.2.2.rc1 app/models/active_storage/blob/identifiable.rb