1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
rails--rails/activestorage/app/models/active_storage/blob/identifiable.rb

21 lines
471 B
Ruby
Raw Normal View History

2018-01-15 13:06:17 -05:00
# frozen_string_literal: true
module ActiveStorage::Blob::Identifiable
def identify
update! content_type: identify_content_type, identified: true unless identified?
2018-01-15 13:06:17 -05:00
end
def identified?
identified
end
2018-02-20 18:08:14 -05:00
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
2018-02-20 18:08:14 -05:00
end
2018-01-15 13:06:17 -05:00
end