diff options
author | George Claghorn <george@basecamp.com> | 2018-02-20 18:08:14 -0500 |
---|---|---|
committer | George Claghorn <george@basecamp.com> | 2018-02-20 18:08:14 -0500 |
commit | 9794e85351243cac6d4e78adaba634b8e4ecad0a (patch) | |
tree | 6faaacbb28740204cadf52146d63ecc687d59d98 /activestorage/app/models | |
parent | d94db077746cd47d99a9ab1f98ee5fcda5642893 (diff) | |
download | rails-9794e85351243cac6d4e78adaba634b8e4ecad0a.tar.gz rails-9794e85351243cac6d4e78adaba634b8e4ecad0a.tar.bz2 rails-9794e85351243cac6d4e78adaba634b8e4ecad0a.zip |
Hoist update for clarity
Diffstat (limited to 'activestorage/app/models')
-rw-r--r-- | activestorage/app/models/active_storage/blob/identifiable.rb | 7 | ||||
-rw-r--r-- | activestorage/app/models/active_storage/identification.rb | 9 |
2 files changed, 8 insertions, 8 deletions
diff --git a/activestorage/app/models/active_storage/blob/identifiable.rb b/activestorage/app/models/active_storage/blob/identifiable.rb index 40ca84ac70..dbe03cfa6c 100644 --- a/activestorage/app/models/active_storage/blob/identifiable.rb +++ b/activestorage/app/models/active_storage/blob/identifiable.rb @@ -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 diff --git a/activestorage/app/models/active_storage/identification.rb b/activestorage/app/models/active_storage/identification.rb index 6f55418cd8..8d334ae1ea 100644 --- a/activestorage/app/models/active_storage/identification.rb +++ b/activestorage/app/models/active_storage/identification.rb @@ -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 |