Sha256: 29b06ebf4e34536ef543f1def8e5a0ee403d9f416631f6ea962ee501e3224189

Contents?: true

Size: 632 Bytes

Versions: 76

Compression:

Stored size: 632 Bytes

Contents

# frozen_string_literal: true

module ActiveStorage::Blob::Identifiable
  def identify
    identify_without_saving
    save!
  end

  def identify_without_saving
    unless identified?
      self.content_type = identify_content_type
      self.identified = true
    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
end

Version data entries

76 entries across 72 versions & 7 rubygems

Version Path
trusty-cms-7.0.9.1 vendor/bundle/ruby/3.3.0/gems/activestorage-7.0.8.7/app/models/active_storage/blob/identifiable.rb
activestorage-7.0.8.7 app/models/active_storage/blob/identifiable.rb
activestorage-7.0.8.6 app/models/active_storage/blob/identifiable.rb
activestorage-6.1.7.10 app/models/active_storage/blob/identifiable.rb
activestorage-6.1.7.9 app/models/active_storage/blob/identifiable.rb
activestorage-7.0.8.5 app/models/active_storage/blob/identifiable.rb
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/activestorage-7.0.8.4/app/models/active_storage/blob/identifiable.rb
cm-admin-1.5.22 vendor/bundle/ruby/3.3.0/gems/activestorage-7.0.5.1/app/models/active_storage/blob/identifiable.rb
cm-admin-1.5.21 vendor/bundle/ruby/3.3.0/gems/activestorage-7.0.5.1/app/models/active_storage/blob/identifiable.rb
cm-admin-1.5.20 vendor/bundle/ruby/3.3.0/gems/activestorage-7.0.5.1/app/models/active_storage/blob/identifiable.rb
activestorage-7.0.8.4 app/models/active_storage/blob/identifiable.rb
activestorage-6.1.7.8 app/models/active_storage/blob/identifiable.rb
activestorage-7.0.8.1 app/models/active_storage/blob/identifiable.rb
activestorage-6.1.7.7 app/models/active_storage/blob/identifiable.rb
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/activestorage-7.0.3.1/app/models/active_storage/blob/identifiable.rb
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/activestorage-7.0.2.3/app/models/active_storage/blob/identifiable.rb
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/activestorage-6.1.6.1/app/models/active_storage/blob/identifiable.rb
activestorage-7.0.8 app/models/active_storage/blob/identifiable.rb
activestorage-7.0.7.2 app/models/active_storage/blob/identifiable.rb
activestorage-6.1.7.6 app/models/active_storage/blob/identifiable.rb