public
Description: Rails plugin for uploading images as resources, with support for resizing, text stamping, and other special effects.
Homepage: http://wiki.github.com/Squeegy/fleximage
Clone URL: git://github.com/Squeegy/fleximage.git
Fixed that an error would sometimes occur on deleting an abstract image model.  
Also, magic columns are cleared when #delete_image_file is called.  [#2 
status:resolved]
Squeegy (author)
Mon Jun 09 20:50:21 -0700 2008
commit  192ddcb95af577e9e390ea13b24fa27470844d32
tree    93058d175e4a9751d4340c7c376419b624297ebf
parent  6c6051daa04dc5b5eb419275bf33b7710c842bea
...
377
378
379
380
 
 
 
 
 
 
 
 
 
 
 
381
382
383
...
434
435
436
 
 
 
 
 
 
 
 
437
438
439
...
377
378
379
 
380
381
382
383
384
385
386
387
388
389
390
391
392
393
...
444
445
446
447
448
449
450
451
452
453
454
455
456
457
0
@@ -377,7 +377,17 @@ module Fleximage
0
       # Delete the image file for this record. This is automatically ran after this record gets 
0
       # destroyed, but you can call it manually if you want to remove the image from the record.
0
       def delete_image_file
0
-        File.delete(file_path) if !self.class.db_store? && File.exists?(file_path)
0
+        return unless self.class.has_store?
0
+        
0
+        if self.class.db_store?
0
+          update_attribute :image_file_data, nil unless frozen?
0
+        else
0
+          File.delete(file_path) && File.exists?(file_path)
0
+        end
0
+        
0
+        clear_magic_attributes
0
+        
0
+        self
0
       end
0
       
0
       # Execute image presence and validity validations.
0
@@ -434,6 +444,14 @@ module Fleximage
0
           end
0
         end
0
         
0
+        def clear_magic_attributes
0
+          unless frozen?
0
+            self.image_filename = nil if respond_to?(:image_filename=)
0
+            self.image_width    = nil if respond_to?(:image_width=)
0
+            self.image_height   = nil if respond_to?(:image_height=)
0
+          end
0
+        end
0
+        
0
         # If any magic column names exists fill them with image meta data.
0
         def set_magic_attributes(file = nil)
0
           if file && self.respond_to?(:image_filename=)
...
16
17
18
 
 
 
 
 
 
 
 
 
 
 
19
...
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
0
@@ -16,4 +16,15 @@ class FleximageMagicColumnsTest < Test::Unit::TestCase
0
   rescue SocketError
0
     print '!'
0
   end
0
+  
0
+  def test_should_delete_magic_columns_when_image_is_deleted
0
+    p = PhotoFile.new(:image_file => files(:photo))
0
+    p.save
0
+    
0
+    p = PhotoFile.find(p.id)
0
+    p.delete_image_file.save
0
+    
0
+    assert_nil p.image_width
0
+    assert_nil p.image_height
0
+  end
0
 end

Comments