2018-01-15 13:06:17 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module ActiveStorage::Blob::Identifiable
|
|
|
|
def identify
|
2018-03-05 11:53:31 -05:00
|
|
|
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
|
2018-03-05 11:53:31 -05:00
|
|
|
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
|