Skip to content

Commit

Permalink
Replace mime-types gem with mini_mime
Browse files Browse the repository at this point in the history
  • Loading branch information
bradleypriest committed Mar 11, 2018
1 parent f64f499 commit e6910e7
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 22 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -4,6 +4,8 @@ All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]
### Changed
* Replace mime-types dependency with mini_mime(@bradleypriest [#2281](https://github.com/carrierwaveuploader/carrierwave/pull/2281))

## 1.2.2 - 2018-01-02
### Fixed
Expand Down
2 changes: 1 addition & 1 deletion carrierwave.gemspec
Expand Up @@ -23,7 +23,7 @@ Gem::Specification.new do |s|

s.add_dependency "activesupport", ">= 4.0.0"
s.add_dependency "activemodel", ">= 4.0.0"
s.add_dependency "mime-types", ">= 1.16"
s.add_dependency "mini_mime", ">= 0.1.3"
if RUBY_ENGINE == 'jruby'
s.add_development_dependency 'activerecord-jdbcpostgresql-adapter'
else
Expand Down
2 changes: 1 addition & 1 deletion lib/carrierwave/processing/mini_magick.rb
Expand Up @@ -310,7 +310,7 @@ def manipulate!

if @format
move_to = current_path.chomp(File.extname(current_path)) + ".#{@format}"
file.content_type = ::MIME::Types.type_for(move_to).first.to_s
file.content_type = ::MiniMime.lookup_by_filename(move_to).content_type
file.move_to(move_to, permissions, directory_permissions)
end

Expand Down
2 changes: 1 addition & 1 deletion lib/carrierwave/processing/rmagick.rb
Expand Up @@ -363,7 +363,7 @@ def manipulate!(options={}, &block)
if options[:format] || @format
frames.write("#{options[:format] || @format}:#{current_path}", &write_block)
move_to = current_path.chomp(File.extname(current_path)) + ".#{options[:format] || @format}"
file.content_type = ::MIME::Types.type_for(move_to).first.to_s
file.content_type = ::MiniMime.lookup_by_filename(move_to).content_type
file.move_to(move_to, permissions, directory_permissions)
else
frames.write(current_path, &write_block)
Expand Down
17 changes: 8 additions & 9 deletions lib/carrierwave/sanitized_file.rb
@@ -1,12 +1,6 @@
require 'pathname'
require 'active_support/core_ext/string/multibyte'

begin
# Use mime/types/columnar if available, for reduced memory usage
require 'mime/types/columnar'
rescue LoadError
require 'mime/types'
end
require 'mini_mime'

module CarrierWave

Expand Down Expand Up @@ -267,9 +261,14 @@ def to_file
def content_type
return @content_type if @content_type
if @file.respond_to?(:content_type) and @file.content_type
@content_type = @file.content_type.to_s.chomp
if @file.content_type.respond_to?(:content_type)
@content_type = @file.content_type.content_type.chomp
else
@content_type = @file.content_type.to_s.chomp
end
elsif path
@content_type = ::MIME::Types.type_for(path).first.to_s
mime_type = ::MiniMime.lookup_by_filename(path)
@content_type = (mime_type && mime_type.content_type).to_s
end
end

Expand Down
4 changes: 2 additions & 2 deletions lib/carrierwave/uploader/download.rb
Expand Up @@ -18,9 +18,9 @@ def initialize(uri, remote_headers = {})

def original_filename
filename = filename_from_header || filename_from_uri
mime_type = MIME::Types[file.content_type].first
mime_type = MiniMime.lookup_by_content_type(file.content_type)
unless File.extname(filename).present? || mime_type.blank?
filename = "#{filename}.#{mime_type.extensions.first}"
filename = "#{filename}.#{mime_type.extension}"
end
filename
end
Expand Down
10 changes: 2 additions & 8 deletions spec/sanitized_file_spec.rb
@@ -1,11 +1,5 @@
require 'spec_helper'

begin
# Use mime/types/columnar if available, for reduced memory usage
require 'mime/types/columnar'
rescue LoadError
require 'mime/types'
end
require 'mini_mime'

describe CarrierWave::SanitizedFile do
before do
Expand Down Expand Up @@ -189,7 +183,7 @@

it "handles Mime::Type object" do
file = File.open(file_path('sponsored.doc'))
allow(file).to receive(:content_type).and_return(MIME::Type.new("application/msword"))
allow(file).to receive(:content_type).and_return(MiniMime.lookup_by_content_type("application/msword"))
sanitized_file = CarrierWave::SanitizedFile.new(file)
allow(sanitized_file).to receive(:file).and_return(file)

Expand Down

0 comments on commit e6910e7

Please sign in to comment.