Sha256: 89f2aef24985dbd408cc77e74315dbc6f6f322361a472021ae521a5743be5267

Contents?: true

Size: 698 Bytes

Versions: 22

Compression:

Stored size: 698 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

22 entries across 22 versions & 1 rubygems

Version Path
activestorage-6.0.6.1 app/models/active_storage/blob/identifiable.rb
activestorage-6.0.6 app/models/active_storage/blob/identifiable.rb
activestorage-6.0.5.1 app/models/active_storage/blob/identifiable.rb
activestorage-6.0.5 app/models/active_storage/blob/identifiable.rb
activestorage-6.0.4.8 app/models/active_storage/blob/identifiable.rb
activestorage-6.0.4.7 app/models/active_storage/blob/identifiable.rb
activestorage-6.0.4.6 app/models/active_storage/blob/identifiable.rb
activestorage-6.0.4.5 app/models/active_storage/blob/identifiable.rb
activestorage-6.0.4.4 app/models/active_storage/blob/identifiable.rb
activestorage-6.0.4.3 app/models/active_storage/blob/identifiable.rb
activestorage-6.0.4.2 app/models/active_storage/blob/identifiable.rb
activestorage-6.0.4.1 app/models/active_storage/blob/identifiable.rb
activestorage-6.0.4 app/models/active_storage/blob/identifiable.rb
activestorage-6.0.3.7 app/models/active_storage/blob/identifiable.rb
activestorage-6.0.3.6 app/models/active_storage/blob/identifiable.rb
activestorage-6.0.3.5 app/models/active_storage/blob/identifiable.rb
activestorage-6.0.3.4 app/models/active_storage/blob/identifiable.rb
activestorage-6.0.3.3 app/models/active_storage/blob/identifiable.rb
activestorage-6.0.3.2 app/models/active_storage/blob/identifiable.rb
activestorage-6.0.3.1 app/models/active_storage/blob/identifiable.rb