Commit ffb0e01b by Henrik N

Shorten !attachment.original_filename.blank? to attachment.file?

parent 71adf38c
...@@ -135,7 +135,7 @@ module Paperclip ...@@ -135,7 +135,7 @@ module Paperclip
end end
define_method "#{name}?" do define_method "#{name}?" do
! attachment_for(name).original_filename.blank? attachment_for(name).file?
end end
validates_each(name) do |record, attr, value| validates_each(name) do |record, attr, value|
...@@ -157,7 +157,8 @@ module Paperclip ...@@ -157,7 +157,8 @@ module Paperclip
unless options[:less_than].nil? unless options[:less_than].nil?
options[:in] = (0..options[:less_than]) options[:in] = (0..options[:less_than])
end end
unless attachment.original_filename.blank? || options[:in].include?(instance[:"#{name}_file_size"].to_i)
if attachment.file? && !options[:in].include?(instance[:"#{name}_file_size"].to_i)
min = options[:in].first min = options[:in].first
max = options[:in].last max = options[:in].last
...@@ -178,7 +179,7 @@ module Paperclip ...@@ -178,7 +179,7 @@ module Paperclip
# Places ActiveRecord-style validations on the presence of a file. # Places ActiveRecord-style validations on the presence of a file.
def validates_attachment_presence name, options = {} def validates_attachment_presence name, options = {}
attachment_definitions[name][:validations] << lambda do |attachment, instance| attachment_definitions[name][:validations] << lambda do |attachment, instance|
if attachment.original_filename.blank? unless attachment.file?
options[:message] || "must be set." options[:message] || "must be set."
end end
end end
......
...@@ -187,6 +187,10 @@ module Paperclip ...@@ -187,6 +187,10 @@ module Paperclip
true true
end end
end end
def file?
!original_filename.blank?
end
private private
...@@ -249,7 +253,7 @@ module Paperclip ...@@ -249,7 +253,7 @@ module Paperclip
end end
def queue_existing_for_delete #:nodoc: def queue_existing_for_delete #:nodoc:
return if original_filename.blank? return unless file?
logger.info("[paperclip] Queueing the existing files for #{name} for deletion.") logger.info("[paperclip] Queueing the existing files for #{name} for deletion.")
@queued_for_delete += [:original, *@styles.keys].uniq.map do |style| @queued_for_delete += [:original, *@styles.keys].uniq.map do |style|
path(style) if exists?(style) path(style) if exists?(style)
......
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