Commit 9ecd52ea by Stephen Pike

Fix some style guide issues

parent 2a0274d1
......@@ -54,24 +54,26 @@ module Paperclip
end
def calculated_type_matches
possible_types.select { |content_type| content_type == type_from_file_contents }
possible_types.select do |content_type|
content_type == type_from_file_contents
end
end
def type_from_file_contents
type = begin
type_from_mime_magic || type_from_file_command
rescue Errno::ENOENT => e
Paperclip.log("Error while determining content type: #{e}")
SENSIBLE_DEFAULT
end
end
def type_from_file_command
@type_from_file_command ||= FileCommandContentTypeDetector.new(@filename).detect
@type_from_file_command ||=
FileCommandContentTypeDetector.new(@filename).detect
end
def type_from_mime_magic
@type_from_mime_magic ||= MimeMagic.by_magic(File.open(@filename)).try(:type)
@type_from_mime_magic ||=
MimeMagic.by_magic(File.open(@filename)).try(:type)
end
end
end
......@@ -13,8 +13,8 @@ module Paperclip
private
def type_from_file_command
type = begin
# On BSDs, `file` doesn't give a result code of 1 if the file doesn't exist.
type = begin
Paperclip.run("file", "-b --mime :file", file: @filename)
rescue Cocaine::CommandLineError => e
Paperclip.log("Error while determining content type: #{e}")
......
......@@ -19,7 +19,8 @@ describe Paperclip::ContentTypeDetector do
it 'returns content type of file if it is an acceptable type' do
MIME::Types.stubs(:type_for).returns([MIME::Type.new('application/mp4'), MIME::Type.new('video/mp4'), MIME::Type.new('audio/mp4')])
Paperclip::ContentTypeDetector.any_instance.stubs(:type_from_file_contents).returns("video/mp4")
Paperclip::ContentTypeDetector.any_instance
.stubs(:type_from_file_contents).returns("video/mp4")
@filename = "my_file.mp4"
assert_equal "video/mp4", Paperclip::ContentTypeDetector.new(@filename).detect
end
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment