paperdragon 0.0.2 → 0.0.3
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.
- checksums.yaml +4 -4
- data/lib/paperdragon/attachment.rb +8 -1
- data/lib/paperdragon/paperclip/model.rb +2 -2
- data/lib/paperdragon/version.rb +1 -1
- data/test/task_test.rb +22 -8
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9af7c068f42c32dc239fc8cf84be2c3bfda25d11
|
4
|
+
data.tar.gz: b1825d0e36536161bca66c9dd35f0ab035ed6260
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8ac3fa592390c0dafe14c82697985f4b086ae9fc03c2ca1df219d24ec7ce7b4845a03278fb5f77999bc767d54b86b9767540505140a14aa6e116469e465785ce
|
7
|
+
data.tar.gz: e1bac84bb7d1e9e7f8404425980b723733fa3baf2ef09b0af681b6bce4de007a2d324e7713792ab680c6175ef9b347978481a660d9e12a3edf69af0e5103ea33
|
@@ -36,10 +36,17 @@ module Paperdragon
|
|
36
36
|
task.metadata_hash
|
37
37
|
end
|
38
38
|
|
39
|
+
# Per default, paperdragon tries to increment the fingerprint in the file name, identified by
|
40
|
+
# the pattern <tt>/-\d{10}/</tt> just before the filename extension (.png).
|
39
41
|
def rebuild_uid(file, fingerprint=nil) # the signature of this method is to be considered semi-private.
|
40
42
|
ext = ::File.extname(file.uid)
|
41
43
|
name = ::File.basename(file.uid, ext)
|
42
|
-
|
44
|
+
|
45
|
+
if fingerprint and matches = name.match(/-(\d{10})$/)
|
46
|
+
return file.uid.sub(matches[1], fingerprint.to_s)
|
47
|
+
end
|
48
|
+
|
49
|
+
file.uid.sub(name, "#{name}-#{fingerprint}")
|
43
50
|
end
|
44
51
|
|
45
52
|
def exists? # should be #uploaded? or #stored?
|
@@ -31,8 +31,8 @@ module Paperdragon
|
|
31
31
|
@attachment[style].url # Avatar::Photo.new(avatar, :thumb).url
|
32
32
|
end
|
33
33
|
|
34
|
-
def method_missing(name, *args)
|
35
|
-
@attachment.send(name, *args)
|
34
|
+
def method_missing(name, *args, &block)
|
35
|
+
@attachment.send(name, *args, &block)
|
36
36
|
end
|
37
37
|
end
|
38
38
|
end
|
data/lib/paperdragon/version.rb
CHANGED
data/test/task_test.rb
CHANGED
@@ -51,14 +51,13 @@ class TaskSpec < MiniTest::Spec
|
|
51
51
|
:original=>{:uid=>"original/pic.jpg"}, :thumb=>{:uid=>"original/thumb.jpg"}}).task
|
52
52
|
}
|
53
53
|
|
54
|
-
# FIXME: fingerprint should be added before .png suffix, idiot!
|
55
54
|
it do
|
56
|
-
subject.reprocess!(:original, "
|
57
|
-
subject.reprocess!(:thumb, "
|
55
|
+
subject.reprocess!(:original, "1", original)
|
56
|
+
subject.reprocess!(:thumb, "1", original) { |j| j.thumb!("16x16") }
|
58
57
|
|
59
|
-
#
|
58
|
+
# FIXME: fingerprint should be added before .png suffix.
|
60
59
|
subject.metadata_hash.must_equal({:original=>{:width=>216, :height=>63, :uid=>"original/pic-1.jpg"}, :thumb=>{:width=>16, :height=>5, :uid=>"original/thumb-1.jpg"}})
|
61
|
-
|
60
|
+
|
62
61
|
# exists?(original.uri).must_equal false # deleted
|
63
62
|
# exists?(new_uid).must_equal true
|
64
63
|
end
|
@@ -66,17 +65,32 @@ class TaskSpec < MiniTest::Spec
|
|
66
65
|
# don't pass in fingerprint+original.
|
67
66
|
it do
|
68
67
|
subject.reprocess!(:thumb) { |j| j.thumb!("24x24") }
|
69
|
-
subject.metadata_hash.must_equal({:original=>{:uid=>"original/pic.jpg"}, :thumb=>{:width=>24, :height=>7, :uid=>"original/thumb
|
68
|
+
subject.metadata_hash.must_equal({:original=>{:uid=>"original/pic.jpg"}, :thumb=>{:width=>24, :height=>7, :uid=>"original/thumb-.jpg"}})
|
70
69
|
end
|
71
70
|
|
72
71
|
# only process one, should return entire metadata hash
|
73
72
|
it do
|
74
|
-
subject.reprocess!(:thumb, "
|
73
|
+
subject.reprocess!(:thumb, "new") { |j| j.thumb!("24x24") }
|
75
74
|
subject.metadata_hash.must_equal({:original=>{:uid=>"original/pic.jpg"}, :thumb=>{:width=>24, :height=>7, :uid=>"original/thumb-new.jpg"}})
|
76
75
|
|
77
76
|
# original must be unchanged
|
78
77
|
exists?(Attachment.new(subject.metadata_hash)[:original].uid).must_equal true
|
79
78
|
end
|
79
|
+
|
80
|
+
# #rebuild_uid tries to replace existing fingerprint (default behaviour).
|
81
|
+
it do
|
82
|
+
subject.reprocess!(:thumb, "1234567890") { |j| j.thumb!("24x24") }
|
83
|
+
metadata = subject.metadata_hash
|
84
|
+
metadata.must_equal({:original=>{:uid=>"original/pic.jpg"}, :thumb=>{:width=>24, :height=>7, :uid=>"original/thumb-1234567890.jpg"}})
|
85
|
+
|
86
|
+
# this might happen in the next request.
|
87
|
+
subject = Attachment.new(metadata).task
|
88
|
+
subject.reprocess!(:thumb, "0987654321") { |j| j.thumb!("24x24") }
|
89
|
+
subject.metadata_hash.must_equal({:original=>{:uid=>"original/pic.jpg"}, :thumb=>{:width=>24, :height=>7, :uid=>"original/thumb-0987654321.jpg"}})
|
90
|
+
end
|
91
|
+
|
92
|
+
# #rebuild_uid eats integers.
|
93
|
+
it { subject.reprocess!(:thumb, 1234081599) { |j| j.thumb!("24x24") }.must_equal({:original=>{:uid=>"original/pic.jpg"}, :thumb=>{:width=>24, :height=>7, :uid=>"original/thumb-1234081599.jpg"}}) }
|
80
94
|
end
|
81
95
|
|
82
96
|
|
@@ -97,7 +111,7 @@ class TaskSpec < MiniTest::Spec
|
|
97
111
|
it do
|
98
112
|
attachment = Paperdragon::Attachment.new(metadata) # {:original=>{:width=>216, :height=>63, :uid=>"uid/original", :size=>9632}}
|
99
113
|
task = attachment.task
|
100
|
-
task.rename!(:original, "
|
114
|
+
task.rename!(:original, "new") { |uid, new_uid|
|
101
115
|
File.rename("public/paperdragon/"+uid, "public/paperdragon/"+new_uid)
|
102
116
|
}.must_equal({:original=>{:width=>216, :height=>63, :uid=>"original-apotomo-new.png"}})
|
103
117
|
end
|