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-6.0.2.rc2 app/models/active_storage/blob/identifiable.rb
activestorage-5.2.4 app/models/active_storage/blob/identifiable.rb
activestorage-6.0.2.rc1 app/models/active_storage/blob/identifiable.rb
activestorage-5.2.4.rc1 app/models/active_storage/blob/identifiable.rb
activestorage-6.0.1 app/models/active_storage/blob/identifiable.rb
chatops-rpc-0.0.2 fixtures/chatops-controller-example/vendor/bundle/ruby/2.5.0/gems/activestorage-6.0.0/app/models/active_storage/blob/identifiable.rb
activestorage-6.0.1.rc1 app/models/active_storage/blob/identifiable.rb
chatops-rpc-0.0.1 fixtures/chatops-controller-example/vendor/bundle/ruby/2.5.0/gems/activestorage-6.0.0/app/models/active_storage/blob/identifiable.rb
activestorage-6.0.0 app/models/active_storage/blob/identifiable.rb
spiral_form-0.1.1 vendor/bundle/gems/activestorage-5.2.3/app/models/active_storage/blob/identifiable.rb
spiral_form-0.1.0 vendor/bundle/gems/activestorage-5.2.3/app/models/active_storage/blob/identifiable.rb
activestorage-6.0.0.rc2 app/models/active_storage/blob/identifiable.rb
activestorage-6.0.0.rc1 app/models/active_storage/blob/identifiable.rb
activestorage-5.2.3 app/models/active_storage/blob/identifiable.rb
activestorage-5.2.3.rc1 app/models/active_storage/blob/identifiable.rb
activestorage-6.0.0.beta3 app/models/active_storage/blob/identifiable.rb
activestorage-5.2.2.1 app/models/active_storage/blob/identifiable.rb
activestorage-6.0.0.beta2 app/models/active_storage/blob/identifiable.rb
activestorage-6.0.0.beta1 app/models/active_storage/blob/identifiable.rb
activestorage-5.2.2 app/models/active_storage/blob/identifiable.rb