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.8.1 app/models/active_storage/blob/identifiable.rb
activestorage-5.2.8 app/models/active_storage/blob/identifiable.rb
activestorage-5.2.7.1 app/models/active_storage/blob/identifiable.rb
activestorage-5.2.7 app/models/active_storage/blob/identifiable.rb
activestorage-5.2.6.3 app/models/active_storage/blob/identifiable.rb
activestorage-5.2.6.2 app/models/active_storage/blob/identifiable.rb
activestorage-5.2.6.1 app/models/active_storage/blob/identifiable.rb
activestorage-5.2.6 app/models/active_storage/blob/identifiable.rb
activestorage-5.2.4.6 app/models/active_storage/blob/identifiable.rb
activestorage-5.2.5 app/models/active_storage/blob/identifiable.rb
activestorage-5.2.4.5 app/models/active_storage/blob/identifiable.rb
activestorage-5.2.4.4 app/models/active_storage/blob/identifiable.rb
activestorage-5.2.4.3 app/models/active_storage/blob/identifiable.rb
activestorage-6.0.2.2 app/models/active_storage/blob/identifiable.rb
activestorage-5.2.4.2 app/models/active_storage/blob/identifiable.rb
argon-1.3.1 vendor/bundle/ruby/2.7.0/gems/activestorage-6.0.2.1/app/models/active_storage/blob/identifiable.rb
symbolic_enum-1.1.5 vendor/bundle/ruby/2.7.0/gems/activestorage-6.0.2.1/app/models/active_storage/blob/identifiable.rb
activestorage-6.0.2.1 app/models/active_storage/blob/identifiable.rb
activestorage-5.2.4.1 app/models/active_storage/blob/identifiable.rb
activestorage-6.0.2 app/models/active_storage/blob/identifiable.rb