Sha256: ba8bcadcf313dcda63b22920bb07061e74a716175432474140c2c8a3dd29731f

Contents?: true

Size: 633 Bytes

Versions: 1

Compression:

Stored size: 633 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
      service.download_chunk key, 0...4.kilobytes
    end

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

Version data entries

1 entries across 1 versions & 1 rubygems

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