lib/paperdragon/model.rb in paperdragon-0.0.4 vs lib/paperdragon/model.rb in paperdragon-0.0.5

- old
+ new

@@ -11,11 +11,16 @@ private # Creates Avatar#image that returns a Paperdragon::File instance. def attachment_accessor_for(name, attachment_class) mod = Module.new do # TODO: abstract that into Uber, we use it everywhere. - define_method name do - attachment_class.new(self.image_meta_data, {:model => self}) + define_method name do |file=nil, &block| + attachment = attachment_class.new(self.image_meta_data, {:model => self}) + + return attachment unless file or block + + # run the task block and save the returned new metadata in the model. + self.image_meta_data = attachment.task(*[file], &block) end end end end end \ No newline at end of file