diff options
author | Ryuta Kamizono <kamipo@gmail.com> | 2017-08-04 09:22:57 +0900 |
---|---|---|
committer | Ryuta Kamizono <kamipo@gmail.com> | 2017-08-05 08:10:13 +0900 |
commit | 6768390a429d43539d72edc710175e3e84e17696 (patch) | |
tree | 2ac23298ee82e3a10ec57be35c968bddb8829ccc /activestorage/app | |
parent | 552840660389e39f3ba8e47dcf35ab817c01cb48 (diff) | |
download | rails-6768390a429d43539d72edc710175e3e84e17696.tar.gz rails-6768390a429d43539d72edc710175e3e84e17696.tar.bz2 rails-6768390a429d43539d72edc710175e3e84e17696.zip |
Use `content_type.start_with?("...")` than `content_type =~ /^.../`
`start_with?` is a little faster than regexp for prefix matching by a
fixed string.
Diffstat (limited to 'activestorage/app')
-rw-r--r-- | activestorage/app/models/active_storage/blob.rb | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/activestorage/app/models/active_storage/blob.rb b/activestorage/app/models/active_storage/blob.rb index debc62bd41..c72073f9f6 100644 --- a/activestorage/app/models/active_storage/blob.rb +++ b/activestorage/app/models/active_storage/blob.rb @@ -80,22 +80,22 @@ class ActiveStorage::Blob < ActiveRecord::Base # Returns true if the content_type of this blob is in the image range, like image/png. def image? - content_type =~ /^image/ + content_type.start_with?("image") end # Returns true if the content_type of this blob is in the audio range, like audio/mpeg. def audio? - content_type =~ /^audio/ + content_type.start_with?("audio") end # Returns true if the content_type of this blob is in the video range, like video/mp4. def video? - content_type =~ /^video/ + content_type.start_with?("video") end # Returns true if the content_type of this blob is in the text range, like text/plain. def text? - content_type =~ /^text/ + content_type.start_with?("text") end # Returns a `ActiveStorage::Variant` instance with the set of `transformations` passed in. This is only relevant |