Permalink
Browse files

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

  • Loading branch information...
1 parent 71adf38 commit ffb0e01b8565b8b9104c2781398407e492624a26 @henrik henrik committed Aug 1, 2008
Showing with 9 additions and 4 deletions.
  1. +4 −3 lib/paperclip.rb
  2. +5 −1 lib/paperclip/attachment.rb
View
@@ -135,7 +135,7 @@ def has_attached_file name, options = {}
end
define_method "#{name}?" do
- ! attachment_for(name).original_filename.blank?
+ attachment_for(name).file?
end
validates_each(name) do |record, attr, value|
@@ -157,7 +157,8 @@ def validates_attachment_size name, options = {}
unless options[:less_than].nil?
options[:in] = (0..options[:less_than])
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
max = options[:in].last
@@ -178,7 +179,7 @@ def validates_attachment_thumbnails name, options = {}
# Places ActiveRecord-style validations on the presence of a file.
def validates_attachment_presence name, options = {}
attachment_definitions[name][:validations] << lambda do |attachment, instance|
- if attachment.original_filename.blank?
+ unless attachment.file?
options[:message] || "must be set."
end
end
@@ -187,6 +187,10 @@ def reprocess!
true
end
end
+
+ def file?
+ !original_filename.blank?
+ end
private
@@ -249,7 +253,7 @@ def interpolate pattern, style = default_style #:nodoc:
end
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.")
@queued_for_delete += [:original, *@styles.keys].uniq.map do |style|
path(style) if exists?(style)

0 comments on commit ffb0e01

Please sign in to comment.