has_image 0.1.4 → 0.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG +5 -0
- data/lib/has_image/storage.rb +1 -1
- data/lib/has_image.rb +12 -0
- data/test_rails/pic_test.rb +2 -0
- metadata +1 -1
data/CHANGELOG
CHANGED
@@ -1,5 +1,10 @@
|
|
1
1
|
2008-07-29 Norman Clarke <norman@randomba.org>
|
2
2
|
|
3
|
+
* Downcased generated file names to avoid potential issues on
|
4
|
+
case-insensitive filesystems.
|
5
|
+
* Added "absolute path" method to model instances.
|
6
|
+
* Made image deletion nullify the "has_image_file" field.
|
7
|
+
* Added "has_image?" method to model instances.
|
3
8
|
* Fixed ENONENT error with record update when there are no images yet.
|
4
9
|
* Reverted thumbnail sorting feature - it's fast but makes terrible quality
|
5
10
|
thumbnails. It's just not worth it.
|
data/lib/has_image/storage.rb
CHANGED
@@ -27,7 +27,7 @@ module HasImage
|
|
27
27
|
# helps prevent a possibly undesirable sitation where the uploaded images
|
28
28
|
# have offensive names.
|
29
29
|
def random_file_name
|
30
|
-
Zlib.crc32(Time.now.to_s + rand(10e10).to_s).to_s(36)
|
30
|
+
Zlib.crc32(Time.now.to_s + rand(10e10).to_s).to_s(36).downcase
|
31
31
|
end
|
32
32
|
|
33
33
|
end
|
data/lib/has_image.rb
CHANGED
@@ -171,6 +171,11 @@ module HasImage
|
|
171
171
|
|
172
172
|
module ModelInstanceMethods
|
173
173
|
|
174
|
+
# Does the object have an image?
|
175
|
+
def has_image?
|
176
|
+
!has_image_file.blank?
|
177
|
+
end
|
178
|
+
|
174
179
|
# Sets the uploaded image data. Image data can be an instance of Tempfile,
|
175
180
|
# or an instance of any class than inherits from IO.
|
176
181
|
def image_data=(image_data)
|
@@ -195,11 +200,18 @@ module HasImage
|
|
195
200
|
def public_path(thumbnail = nil)
|
196
201
|
storage.public_path_for(self, thumbnail)
|
197
202
|
end
|
203
|
+
|
204
|
+
# Gets the absolute filesystem path for the image, or optionally, its
|
205
|
+
# thumbnail.
|
206
|
+
def absolute_path(thumbnail = nil)
|
207
|
+
storage.filesystem_path_for(self, thumbnail)
|
208
|
+
end
|
198
209
|
|
199
210
|
# Deletes the image from the storage.
|
200
211
|
def remove_images
|
201
212
|
return if has_image_file.blank?
|
202
213
|
storage.remove_images(self.id)
|
214
|
+
update_attribute(:has_image_file, nil)
|
203
215
|
rescue Errno::ENOENT
|
204
216
|
logger.warn("Could not delete files for #{self.class.to_s} #{to_param}")
|
205
217
|
end
|
data/test_rails/pic_test.rb
CHANGED