Hoist update for clarity

This commit is contained in:
George Claghorn 2018-02-20 18:08:14 -05:00
parent d94db07774
commit 9794e85351
2 changed files with 8 additions and 8 deletions

View File

@ -2,10 +2,15 @@
module ActiveStorage::Blob::Identifiable
def identify
ActiveStorage::Identification.new(self).apply
update!(content_type: identification.content_type, identified: true) unless identified?
end
def identified?
identified
end
private
def identification
ActiveStorage::Identification.new self
end
end

View File

@ -9,16 +9,11 @@ class ActiveStorage::Identification #:nodoc:
@blob = blob
end
def apply
blob.update!(content_type: content_type, identified: true) unless blob.identified?
def content_type
Marcel::MimeType.for(identifiable_chunk, name: filename, declared_type: declared_content_type)
end
private
def content_type
Marcel::MimeType.for(identifiable_chunk, name: filename, declared_type: declared_content_type)
end
def identifiable_chunk
Net::HTTP.start(uri.host, uri.port, use_ssl: uri.scheme == "https") do |client|
client.get(uri, "Range" => "bytes=0-4095").body