lib/paperdragon/task.rb in paperdragon-0.0.8 vs lib/paperdragon/task.rb in paperdragon-0.0.9
- old
+ new
@@ -1,7 +1,10 @@
module Paperdragon
# Gives a simple API for processing multiple versions of a single attachment.
+ #
+ # Each processing method will return the updated metadata hash. You still have
+ # to save that hash back to the model.
class Task
def initialize(attachment, upload=nil)
@attachment = attachment
@upload = upload
@metadata = attachment.metadata.dup # DISCUSS: keep this dependency?
@@ -38,9 +41,20 @@
def rename!(style, fingerprint, &block)
version = file(style)
new_uid = @attachment.rebuild_uid(version, fingerprint)
@metadata.merge!(style => version.rename!(new_uid, &block))
+ end
+
+ def delete!(*styles)
+ styles = @attachment.metadata.keys if styles.size == 0
+
+ styles.each do |style|
+ file(style).delete!
+ @metadata.delete(style)
+ end
+
+ @metadata
end
private
def file(style, upload=nil)
@attachment[style, upload]
\ No newline at end of file