has_image 0.1.4 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
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.
@@ -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
@@ -36,6 +36,8 @@ class PicTest < Test::Unit::TestCase
36
36
  def test_create
37
37
  @pic = Pic.new(:image_data => fixture_file_upload("/image.jpg", "image/jpeg"))
38
38
  assert @pic.save!
39
+ assert_not_nil @pic.public_path
40
+ assert_not_nil @pic.absolute_path
39
41
  end
40
42
 
41
43
  def test_update
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: has_image
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Norman Clarke