Replace mimemagic with mini_mime

This commit is contained in:
George Claghorn 2021-03-26 08:41:23 -04:00
parent 30ef29289b
commit 62ac25a364
4 changed files with 8 additions and 8 deletions

View File

@ -75,7 +75,7 @@ PATH
activerecord (= 7.0.0.alpha)
activesupport (= 7.0.0.alpha)
marcel (~> 0.3.1)
mimemagic (~> 0.3.2)
mini_mime (~> 1.0.2)
activesupport (7.0.0.alpha)
concurrent-ruby (~> 1.0, >= 1.0.2)
i18n (>= 1.6, < 2)

View File

@ -37,5 +37,5 @@ Gem::Specification.new do |s|
s.add_dependency "activerecord", version
s.add_dependency "marcel", "~> 0.3.1"
s.add_dependency "mimemagic", "~> 0.3.2"
s.add_dependency "mini_mime", "~> 1.0.2"
end

View File

@ -1,6 +1,6 @@
# frozen_string_literal: true
require "mimemagic"
require "mini_mime"
module ActiveStorage::Blob::Representable
extend ActiveSupport::Concern
@ -110,10 +110,10 @@ module ActiveStorage::Blob::Representable
end
def format
if filename.extension.present? && MimeMagic.by_extension(filename.extension)&.to_s == content_type
if filename.extension.present? && MiniMime.lookup_by_extension(filename.extension)&.content_type == content_type
filename.extension
else
MimeMagic.new(content_type).extensions.first
MiniMime.lookup_by_content_type(content_type).extension
end
end

View File

@ -1,6 +1,6 @@
# frozen_string_literal: true
require "mimemagic"
require "mini_mime"
# A set of transformations that can be applied to a blob to create a variant. This class is exposed via
# the ActiveStorage::Blob#variant method and should rarely be used directly.
@ -59,14 +59,14 @@ class ActiveStorage::Variation
def format
transformations.fetch(:format, :png).tap do |format|
if MimeMagic.by_extension(format).nil?
if MiniMime.lookup_by_extension(format.to_s).nil?
raise ArgumentError, "Invalid variant format (#{format.inspect})"
end
end
end
def content_type
MimeMagic.by_extension(format).to_s
MiniMime.lookup_by_extension(format.to_s).content_type
end
# Returns a signed key for all the +transformations+ that this variation was instantiated with.