Commit 30406c61 by Luke Griffiths Committed by Tute Costa

refactor: step-down rule

Present methods in roughly the same order as they are referenced,
to make it more graceful to read without jumping back and forth.
parent 03d14b2e
......@@ -39,26 +39,26 @@ module Paperclip
private
def empty_file?
File.exist?(@filepath) && File.size(@filepath) == 0
end
alias :empty? :empty_file?
def blank_name?
@filepath.nil? || @filepath.empty?
end
def possible_types
MIME::Types.type_for(@filepath).collect(&:content_type)
def empty_file?
File.exist?(@filepath) && File.size(@filepath) == 0
end
alias :empty? :empty_file?
def calculated_type_matches
possible_types.select do |content_type|
content_type == type_from_file_contents
end
end
def possible_types
MIME::Types.type_for(@filepath).collect(&:content_type)
end
def type_from_file_contents
type_from_mime_magic || type_from_file_command
rescue Errno::ENOENT => e
......@@ -66,14 +66,14 @@ module Paperclip
SENSIBLE_DEFAULT
end
def type_from_file_command
@type_from_file_command ||=
FileCommandContentTypeDetector.new(@filepath).detect
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
end
end
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