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 ...@@ -39,26 +39,26 @@ module Paperclip
private private
def empty_file?
File.exist?(@filepath) && File.size(@filepath) == 0
end
alias :empty? :empty_file?
def blank_name? def blank_name?
@filepath.nil? || @filepath.empty? @filepath.nil? || @filepath.empty?
end end
def possible_types def empty_file?
MIME::Types.type_for(@filepath).collect(&:content_type) File.exist?(@filepath) && File.size(@filepath) == 0
end end
alias :empty? :empty_file?
def calculated_type_matches def calculated_type_matches
possible_types.select do |content_type| possible_types.select do |content_type|
content_type == type_from_file_contents content_type == type_from_file_contents
end end
end end
def possible_types
MIME::Types.type_for(@filepath).collect(&:content_type)
end
def type_from_file_contents def type_from_file_contents
type_from_mime_magic || type_from_file_command type_from_mime_magic || type_from_file_command
rescue Errno::ENOENT => e rescue Errno::ENOENT => e
...@@ -66,14 +66,14 @@ module Paperclip ...@@ -66,14 +66,14 @@ module Paperclip
SENSIBLE_DEFAULT SENSIBLE_DEFAULT
end end
def type_from_file_command
@type_from_file_command ||=
FileCommandContentTypeDetector.new(@filepath).detect
end
def type_from_mime_magic def type_from_mime_magic
@type_from_mime_magic ||= @type_from_mime_magic ||=
MimeMagic.by_magic(File.open(@filepath)).try(:type) MimeMagic.by_magic(File.open(@filepath)).try(:type)
end end
def type_from_file_command
@type_from_file_command ||=
FileCommandContentTypeDetector.new(@filepath).detect
end
end 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