lib/paperclip/attachment.rb in jcnetdev-paperclip-1.0.20080704 vs lib/paperclip/attachment.rb in jcnetdev-paperclip-1.1
- old
+ new
@@ -91,10 +91,11 @@
url(style)
end
# Returns true if there are any errors on this attachment.
def valid?
+ validate
errors.length == 0
end
# Returns an array containing the errors on this attachment.
def errors
@@ -157,18 +158,19 @@
# paperclip:refresh rake task and that's it. It will regenerate all thumbnails
# forcefully, by reobtaining the original file and going through the post-process
# again.
def reprocess!
new_original = Tempfile.new("paperclip-reprocess")
- old_original = to_file(:original)
- new_original.write( old_original.read )
- new_original.rewind
+ if old_original = to_file(:original)
+ new_original.write( old_original.read )
+ new_original.rewind
- @queued_for_write = { :original => new_original }
- post_process
+ @queued_for_write = { :original => new_original }
+ post_process
- old_original.close if old_original.respond_to?(:close)
+ old_original.close if old_original.respond_to?(:close)
+ end
end
private
def valid_assignment? file #:nodoc:
@@ -180,10 +182,11 @@
@validation_errors = @validations.collect do |v|
v.call(self, instance)
end.flatten.compact.uniq
@errors += @validation_errors
end
+ @validation_errors
end
def normalize_style_definition
@styles.each do |name, args|
dimensions, format = [args, nil].flatten[0..1]
@@ -200,9 +203,10 @@
def post_process #:nodoc:
return if @queued_for_write[:original].nil?
@styles.each do |name, args|
begin
dimensions, format = args
+ dimensions = dimensions.call(instance) if dimensions.respond_to? :call
@queued_for_write[name] = Thumbnail.make(@queued_for_write[:original],
dimensions,
format,
@whiny_thumnails)
rescue PaperclipError => e