has_image 0.1.8 → 0.1.9
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +3 -0
- data/lib/has_image/storage.rb +14 -8
- data/test/storage_test.rb +4 -3
- metadata +2 -2
data/CHANGELOG
CHANGED
data/lib/has_image/storage.rb
CHANGED
@@ -31,7 +31,7 @@ module HasImage
|
|
31
31
|
# names, and they end up being hard to manipulate on the command line.
|
32
32
|
# This also helps prevent a possibly undesirable sitation where the
|
33
33
|
# uploaded images have offensive names.
|
34
|
-
def
|
34
|
+
def generated_file_name
|
35
35
|
Zlib.crc32(Time.now.to_s + rand(10e10).to_s).to_s(36).downcase
|
36
36
|
end
|
37
37
|
|
@@ -51,7 +51,7 @@ module HasImage
|
|
51
51
|
@temp_file = image_data
|
52
52
|
else
|
53
53
|
image_data.rewind
|
54
|
-
@temp_file = Tempfile.new 'has_image_data_%s' % Storage.
|
54
|
+
@temp_file = Tempfile.new 'has_image_data_%s' % Storage.generated_file_name
|
55
55
|
@temp_file.write(image_data.read)
|
56
56
|
end
|
57
57
|
end
|
@@ -77,10 +77,10 @@ module HasImage
|
|
77
77
|
# Invokes the processor to resize the image(s) and the installs them to
|
78
78
|
# the appropriate directory.
|
79
79
|
def install_images(id)
|
80
|
-
|
81
|
-
install_main_image(id,
|
82
|
-
install_thumbnails(id,
|
83
|
-
return
|
80
|
+
generated_name = Storage.generated_file_name
|
81
|
+
install_main_image(id, generated_name)
|
82
|
+
install_thumbnails(id, generated_name) if !options[:thumbnails].empty?
|
83
|
+
return generated_name
|
84
84
|
ensure
|
85
85
|
@temp_file.close! if !@temp_file.closed?
|
86
86
|
@temp_file = nil
|
@@ -137,7 +137,10 @@ module HasImage
|
|
137
137
|
def install_main_image(id, name)
|
138
138
|
FileUtils.mkdir_p path_for(id)
|
139
139
|
main = processor.resize(@temp_file, @options[:resize_to])
|
140
|
-
main.
|
140
|
+
main.tempfile.close
|
141
|
+
file = File.open(File.join(path_for(id), file_name_for(name)), "w")
|
142
|
+
file.write(IO.read(main.tempfile.path))
|
143
|
+
file.close
|
141
144
|
main.tempfile.close!
|
142
145
|
end
|
143
146
|
|
@@ -148,7 +151,10 @@ module HasImage
|
|
148
151
|
path = File.join(path_for(id), file_name_for(name))
|
149
152
|
options[:thumbnails].each do |thumb_name, size|
|
150
153
|
thumb = processor.resize(path, size)
|
151
|
-
thumb.
|
154
|
+
thumb.tempfile.close
|
155
|
+
file = File.open(File.join(path_for(id), file_name_for(name, thumb_name)), "w")
|
156
|
+
file.write(IO.read(thumb.tempfile.path))
|
157
|
+
file.close
|
152
158
|
thumb.tempfile.close!
|
153
159
|
end
|
154
160
|
end
|
data/test/storage_test.rb
CHANGED
@@ -25,8 +25,8 @@ class StorageTest < Test::Unit::TestCase
|
|
25
25
|
HasImage::Storage.partitioned_path(867792731)
|
26
26
|
end
|
27
27
|
|
28
|
-
def
|
29
|
-
assert_match(/[a-z0-9]{4,6}/i, HasImage::Storage.
|
28
|
+
def test_generated_file_name
|
29
|
+
assert_match(/[a-z0-9]{4,6}/i, HasImage::Storage.generated_file_name)
|
30
30
|
end
|
31
31
|
|
32
32
|
def test_path_for
|
@@ -61,7 +61,8 @@ class StorageTest < Test::Unit::TestCase
|
|
61
61
|
end
|
62
62
|
|
63
63
|
def test_install_and_remove_images
|
64
|
-
@storage = HasImage::Storage.new(default_options
|
64
|
+
@storage = HasImage::Storage.new(default_options.merge(:thumbnails => {
|
65
|
+
:one => "100x100", :two => "200x200"}))
|
65
66
|
@storage.image_data = temp_file("image.jpg")
|
66
67
|
assert @storage.install_images(1)
|
67
68
|
assert @storage.remove_images(1)
|
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
|
+
version: 0.1.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Norman Clarke
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-08-
|
12
|
+
date: 2008-08-19 00:00:00 -03:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|