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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f827f261f58ce5b096178c2b90010e90a99b8e27
4
- data.tar.gz: f6731a32d9779faab6b1f83da6df1006acab51a4
3
+ metadata.gz: 9af7c068f42c32dc239fc8cf84be2c3bfda25d11
4
+ data.tar.gz: b1825d0e36536161bca66c9dd35f0ab035ed6260
5
5
  SHA512:
6
- metadata.gz: 4481129325b2fa60b3034ae07e1cb4a9e636996f68fc4697c03356863e1e25136f272ae925c12e37ac09b7bff94ebd509d548fa07783df38c957a54e587234ee
7
- data.tar.gz: a39824b4503ef45240a09a80845457194504b954cfe66ee4a865207589f5000be7d57dccbceddded4b328b6c2fb0cfaa387e62974999d2c3e8b7f465155a3866
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
- file.uid.sub(name, "#{name}#{fingerprint}")
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
@@ -1,3 +1,3 @@
1
1
  module Paperdragon
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
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, "-1", original)
57
- subject.reprocess!(:thumb, "-1", original) { |j| j.thumb!("16x16") }
55
+ subject.reprocess!(:original, "1", original)
56
+ subject.reprocess!(:thumb, "1", original) { |j| j.thumb!("16x16") }
58
57
 
59
- # it
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
- # it
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.jpg"}})
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, "-new") { |j| j.thumb!("24x24") }
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, "-new") { |uid, new_uid|
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: paperdragon
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nick Sutterer