Skip to content

Commit

Permalink
Drop mimemagic dependency
Browse files Browse the repository at this point in the history
See thoughtbot#2678 for context
  • Loading branch information
matiasgarciaisaia committed Apr 1, 2021
1 parent 175c91a commit 909ed09
Show file tree
Hide file tree
Showing 5 changed files with 1 addition and 12 deletions.
2 changes: 0 additions & 2 deletions lib/paperclip.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,6 @@
require "mime/types"
end

require 'mimemagic'
require 'mimemagic/overlay'
require 'logger'
require 'cocaine'

Expand Down
7 changes: 1 addition & 6 deletions lib/paperclip/content_type_detector.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,17 +60,12 @@ def possible_types
end

def type_from_file_contents
type_from_mime_magic || type_from_file_command
type_from_file_command
rescue Errno::ENOENT => e
Paperclip.log("Error while determining content type: #{e}")
SENSIBLE_DEFAULT
end

def type_from_mime_magic
@type_from_mime_magic ||=
MimeMagic.by_magic(File.open(@filepath)).try(:type)
end

def type_from_file_command
@type_from_file_command ||=
FileCommandContentTypeDetector.new(@filepath).detect
Expand Down
1 change: 0 additions & 1 deletion paperclip.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ Gem::Specification.new do |s|
s.add_dependency('activesupport', '>= 3.2.0')
s.add_dependency('cocaine', '~> 0.5.5')
s.add_dependency('mime-types')
s.add_dependency('mimemagic', '0.3.0')

s.add_development_dependency('activerecord', '>= 3.2.0')
s.add_development_dependency('shoulda')
Expand Down
1 change: 0 additions & 1 deletion spec/paperclip/io_adapters/abstract_adapter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ def content_type
@adapter = TestAdapter.new
@adapter.stubs(:path).returns("image.png")
Paperclip.stubs(:run).returns("image/png\n")
Paperclip::ContentTypeDetector.any_instance.stubs(:type_from_mime_magic).returns("image/png")
end

it "returns the content type without newline" do
Expand Down
2 changes: 0 additions & 2 deletions spec/paperclip/io_adapters/file_adapter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,6 @@
before do
MIME::Types.stubs(:type_for).returns([])
Paperclip.stubs(:run).returns("application/vnd.ms-office\n")
Paperclip::ContentTypeDetector.any_instance
.stubs(:type_from_mime_magic).returns("application/vnd.ms-office")

@subject = Paperclip.io_adapters.for(@file)
end
Expand Down

0 comments on commit 909ed09

Please sign in to comment.