paperdragon 0.0.8 → 0.0.9

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c572a392762a6e502908b2669acf14b0584f3865
4
- data.tar.gz: 134a7784f0170d5c9aea5343a4217a85458aff1b
3
+ metadata.gz: 14395b1c15c23ae0dd9b68795d714ce399b73c2b
4
+ data.tar.gz: 6b7587815f2a57a3964cfbab14c2c81efbf06c35
5
5
  SHA512:
6
- metadata.gz: c1a60a4f77ad4a151d44f0c36fb578f3b620242e3681874d51ab2e83c787d416b6e659c341c23159e849f048807dd462738f21e99cbbe02102a287400f121331
7
- data.tar.gz: e099ad54ab6ca8657d61695a25793431b669930caaf324baf2d96c13eeebc7793598910a780c6046c6aa39edec1a0e2341d96a814496ac106c94701a7a6ad7b6
6
+ metadata.gz: 1fd4b681f89d0a3edae7a967613db00026df7a60adde0e0b3268df710c83c36a2a0c8405978906f09d4ce65dc154412fd1595eb9114e26047ac95100b9a7f625
7
+ data.tar.gz: 525f69bd268b962dff804f6b169d402b8427d74f517fae18c4c65d34bdb9040429b3c1f20a55d2999c04f9d606765698da9083a38f770b58481220efcb41fc42
data/README.md CHANGED
@@ -173,6 +173,14 @@ end
173
173
 
174
174
  This will also remove the associated metadata from the model.
175
175
 
176
+ You can delete all versions of an attachment by omitting the style.
177
+
178
+ ```ruby
179
+ user.image do |v|
180
+ v.delete! # deletes :original and :thumb.
181
+ end
182
+ ```
183
+
176
184
 
177
185
  ## Replacing Images
178
186
 
@@ -320,7 +328,7 @@ Documentation how to use Sidekiq and paperdragon in Traiblazer will be added sho
320
328
  ## Validations
321
329
 
322
330
  Validating uploads are discussed in the _Callbacks_ chapter of the [Trailblazer
323
- book](https://leanpub.com/trailblazer). We use [file_validators](https://github.com/musaffa/file_validations).
331
+ book](https://leanpub.com/trailblazer). We use [file_validators](https://github.com/musaffa/file_validators).
324
332
 
325
333
  ## Model: Reader and Writer
326
334
 
@@ -1,3 +1,7 @@
1
+ # 0.0.9
2
+
3
+ * Add `Task#delete!` which allows to delete files in task blocks.
4
+
1
5
  # 0.0.8
2
6
 
3
7
  * Introduce `Model::Writer` and `Model::Reader` in case you don't like `Model#image`'s fuzzy API.
@@ -1,5 +1,15 @@
1
1
  module Paperdragon
2
2
  # A physical file with a UID.
3
+ #
4
+ # Files are usually created via an Attachment instance. You can call processing
5
+ # methods on file instances. This will save the file and return the new metadata
6
+ # hash.
7
+ #
8
+ # file = Paperdragon::File.new(uid)
9
+ #
10
+ # metadata = file.reprocess! do |job|
11
+ # job.thumb!("16x16")
12
+ # end
3
13
  class File
4
14
  def initialize(uid, options={})
5
15
  @uid = uid
@@ -1,5 +1,8 @@
1
1
  module Paperdragon
2
2
  # Gives a simple API for processing multiple versions of a single attachment.
3
+ #
4
+ # Each processing method will return the updated metadata hash. You still have
5
+ # to save that hash back to the model.
3
6
  class Task
4
7
  def initialize(attachment, upload=nil)
5
8
  @attachment = attachment
@@ -42,6 +45,17 @@ module Paperdragon
42
45
  @metadata.merge!(style => version.rename!(new_uid, &block))
43
46
  end
44
47
 
48
+ def delete!(*styles)
49
+ styles = @attachment.metadata.keys if styles.size == 0
50
+
51
+ styles.each do |style|
52
+ file(style).delete!
53
+ @metadata.delete(style)
54
+ end
55
+
56
+ @metadata
57
+ end
58
+
45
59
  private
46
60
  def file(style, upload=nil)
47
61
  @attachment[style, upload]
@@ -1,3 +1,3 @@
1
1
  module Paperdragon
2
- VERSION = "0.0.8"
2
+ VERSION = "0.0.9"
3
3
  end
@@ -52,6 +52,12 @@ class PaperdragonModelTest < MiniTest::Spec
52
52
 
53
53
  model.image_meta_data.class.must_equal Hash
54
54
  model.image_meta_data.must_equal({:original=>{:width=>216, :height=>63, :uid=>"original-apotomo.png"}, :thumb=>{:width=>8, :height=>2, :uid=>"thumb-apotomo-1.png"}})
55
+
56
+ model.image do |v|
57
+ v.delete!(:thumb)
58
+ end
59
+
60
+ model.image_meta_data.must_equal({:original=>{:width=>216, :height=>63, :uid=>"original-apotomo.png"}})
55
61
  end
56
62
 
57
63
  # passing options from image(file, {..}) to the Attachment.
@@ -162,4 +162,44 @@ class TaskSpec < MiniTest::Spec
162
162
  }.must_equal({:original=>{:width=>216, :height=>63, :uid=>"original-apotomo-new.png"}})
163
163
  end
164
164
  end
165
+
166
+
167
+ describe "#delete!" do
168
+ before do
169
+ attachment = Paperdragon::Attachment.new(nil)
170
+ @upload_task = attachment.task(logo)
171
+ metadata = @upload_task.process!(:original).must_equal({:original=>{:width=>216, :height=>63, :uid=>"original-apotomo.png"}})
172
+
173
+ # we do not update the attachment from task.
174
+ attachment = Paperdragon::Attachment.new(@upload_task.metadata)
175
+ exists?(attachment[:original].uid).must_equal true
176
+ end
177
+
178
+ let (:metadata) { @upload_task.metadata }
179
+
180
+ # #delete!(:original)
181
+ it do
182
+ attachment = Paperdragon::Attachment.new(metadata) # {:original=>{:width=>216, :height=>63, :uid=>"uid/original", :size=>9632}}
183
+
184
+ attachment.task.delete!(:original).must_equal({})
185
+
186
+ exists?(attachment[:original].uid).must_equal false
187
+ end
188
+
189
+ # #delete no args.
190
+ it do
191
+ metadata = @upload_task.process!(:thumb)
192
+ metadata.must_equal({:original=>{:width=>216, :height=>63, :uid=>"original-apotomo.png"}, :thumb=>{:width=>216, :height=>63, :uid=>"thumb-apotomo.png"}})
193
+
194
+ attachment = Paperdragon::Attachment.new(metadata) # {:original=>{:width=>216, :height=>63, :uid=>"uid/original", :size=>9632}}
195
+ # thumb and original are both there.
196
+ exists?(attachment[:original].uid).must_equal true
197
+ exists?(attachment[:thumb].uid).must_equal true
198
+
199
+ attachment.task.delete!.must_equal({})
200
+
201
+ exists?(attachment[:original].uid).must_equal false
202
+ exists?(attachment[:thumb].uid).must_equal false
203
+ end
204
+ end
165
205
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: paperdragon
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nick Sutterer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-06-25 00:00:00.000000000 Z
11
+ date: 2015-08-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dragonfly
@@ -133,7 +133,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
133
133
  version: '0'
134
134
  requirements: []
135
135
  rubyforge_project:
136
- rubygems_version: 2.2.2
136
+ rubygems_version: 2.4.8
137
137
  signing_key:
138
138
  specification_version: 4
139
139
  summary: Explicit image processing based on Dragonfly with Paperclip compatibility.
@@ -147,3 +147,4 @@ test_files:
147
147
  - test/paperclip_uid_test.rb
148
148
  - test/task_test.rb
149
149
  - test/test_helper.rb
150
+ has_rdoc: