paperdragon 0.0.10 → 0.0.11

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: 2af4cc674da4c766be355baeb541aea52b73a2c0
4
- data.tar.gz: 0fda345ec014359c597b6d090ab4efd23c952021
3
+ metadata.gz: b0e47f031023232bacb633493965d1fcf66bd574
4
+ data.tar.gz: 6b29ce47ff2532945759f39b5d8b4a6e49040425
5
5
  SHA512:
6
- metadata.gz: f4e6cced395393045795cf8674f56b4e8dd8372bf8fa7b995d0cc720681818d295860a63e8c434a29f90ca6399ee5066bf6b60306e4233c1e211d8c61fcc047b
7
- data.tar.gz: 3a3e9e574ad94bdf10ac8ddb06ce4088f2a4a773f57763fd5c70605afffbc1737bcc3eae2cf128201d50ae58b71d026bbb8b96252bca256c1921688f22aeb261
6
+ metadata.gz: d28dc094cd5af5931b7cdad1abd9e87102592bba73fe7f1ce41ce96dd86ab13adbf1d00fcd6d816b3a1e275e1316836fbfb86fe863b1e3566e6f823fed0d180d
7
+ data.tar.gz: 7f6357827527520ebe2557e752712ecd2baa477f68e11b4fb72eb2ae2bb42ebe8399bb58462d0d4c6494f721dff51edbd24db61a8c6afbcaf3fdfddc14a88773
@@ -1,3 +1,16 @@
1
+ # 0.0.11
2
+
3
+ * You can now have any name for attachments in `Model`. This also allows having multiple uploads per model. E.g. the following now works.
4
+
5
+ ```ruby
6
+ processable :avatar, Attachment
7
+ processable :image, Attachment
8
+ ```
9
+
10
+ You will need `avatar_meta_data` and `image_meta_data` fields, now.
11
+
12
+ Many thanks to @mrbongiolo for implementing this.
13
+
1
14
  # 0.0.10
2
15
 
3
16
  * Require Dragonfly 1.0.12 or above and change internal API accordingly. Thanks @acaron for fixing that!
@@ -15,12 +15,13 @@ module Paperdragon
15
15
  def attachment_accessor_for(name, attachment_class)
16
16
  mod = Module.new do # TODO: abstract that into Uber, we use it everywhere.
17
17
  define_method name do |file=nil, options={}, &block|
18
- attachment = attachment_class.new(image_meta_data, options.merge(model: self))
18
+ attachment = attachment_class.new(public_send("#{name}_meta_data"),
19
+ options.merge(model: self))
19
20
 
20
21
  return attachment unless file or block
21
22
 
22
23
  # run the task block and save the returned new metadata in the model.
23
- self.image_meta_data = attachment.task(*[file], &block)
24
+ self.public_send("#{name}_meta_data=", attachment.task(*[file], &block))
24
25
  end
25
26
  end
26
27
  end
@@ -36,10 +37,11 @@ module Paperdragon
36
37
  def processable_writer(name, attachment_class=Attachment)
37
38
  mod = Module.new do # TODO: abstract that into Uber, we use it everywhere.
38
39
  define_method "#{name}!" do |file=nil, options={}, &block|
39
- attachment = attachment_class.new(image_meta_data, options.merge(model: self))
40
+ attachment = attachment_class.new(public_send("#{name}_meta_data"),
41
+ options.merge(model: self))
40
42
 
41
43
  # run the task block and save the returned new metadata in the model.
42
- self.image_meta_data = attachment.task(*[file], &block)
44
+ self.public_send("#{name}_meta_data=", attachment.task(*[file], &block))
43
45
  end
44
46
  end
45
47
  include mod
@@ -55,7 +57,7 @@ module Paperdragon
55
57
  module Reader
56
58
  def processable_reader(name, attachment_class=Attachment)
57
59
  define_method name do
58
- attachment_class.new(image_meta_data, model: self)
60
+ attachment_class.new(public_send("#{name}_meta_data"), model: self)
59
61
  end
60
62
  end
61
63
  end
@@ -13,7 +13,7 @@ module Paperdragon
13
13
  # `image(:thumb).url`.
14
14
  mod = Module.new do # TODO: merge with attachment_accessor_for.
15
15
  define_method name do # e.g. Avatar#image
16
- Proxy.new(self, attachment_class) # provide paperclip DSL.
16
+ Proxy.new(name, self, attachment_class) # provide paperclip DSL.
17
17
  end
18
18
  end
19
19
  include mod
@@ -23,8 +23,8 @@ module Paperdragon
23
23
 
24
24
  # Needed to expose Paperclip's DSL, like avatar.image.url(:thumb).
25
25
  class Proxy
26
- def initialize(model, attachment_class)
27
- @attachment = attachment_class.new(model.image_meta_data, {:model => model})
26
+ def initialize(name, model, attachment_class)
27
+ @attachment = attachment_class.new(model.public_send("#{name}_meta_data"), {:model => model})
28
28
  end
29
29
 
30
30
  def url(style)
@@ -1,3 +1,3 @@
1
1
  module Paperdragon
2
- VERSION = "0.0.10"
2
+ VERSION = "0.0.11"
3
3
  end
@@ -11,32 +11,41 @@ class PaperdragonModelTest < MiniTest::Spec
11
11
 
12
12
  include Paperdragon::Model
13
13
  processable :image, Attachment
14
+ processable :picture, Attachment
14
15
 
15
16
 
16
17
  def image_meta_data
17
18
  {:thumb => {:uid => "Avatar-thumb"}}
18
19
  end
20
+
21
+ def picture_meta_data
22
+ {:thumb => {:uid => "Picture-thumb"}}
23
+ end
19
24
  end
20
25
 
21
26
  # model has image_meta_data hash.
22
27
  it { Avatar.new.image[:thumb].url.must_equal "/paperdragon/Avatar-thumb" }
28
+ it { Avatar.new.picture[:thumb].url.must_equal "/paperdragon/Picture-thumb" }
23
29
  # model doesn't have upload, yet. returns empty attachment.
24
30
  it { Image.new.image.metadata.must_equal({}) }
31
+ it { Image.new.picture.metadata.must_equal({}) }
25
32
 
26
33
 
27
34
  # minimum setup
28
35
  class Image < OpenStruct
29
36
  include Paperdragon::Model
30
37
  processable :image
38
+ processable :picture
31
39
  end
32
40
 
33
41
  it { Image.new(:image_meta_data => {:thumb => {:uid => "Avatar-thumb"}}).image[:thumb].url.must_equal "/paperdragon/Avatar-thumb" }
42
+ it { Image.new(:picture_meta_data => {:thumb => {:uid => "Picture-thumb"}}).picture[:thumb].url.must_equal "/paperdragon/Picture-thumb" }
34
43
 
35
44
 
36
45
  # process with #image{}
37
46
  let (:logo) { Pathname("test/fixtures/apotomo.png") }
38
47
 
39
- it do
48
+ it "image" do
40
49
  model = Image.new
41
50
  model.image(logo) do |v|
42
51
  v.process!(:original)
@@ -60,6 +69,30 @@ class PaperdragonModelTest < MiniTest::Spec
60
69
  model.image_meta_data.must_equal({:original=>{:width=>216, :height=>63, :uid=>"original-apotomo.png"}})
61
70
  end
62
71
 
72
+ it "picture" do
73
+ model = Image.new
74
+ model.picture(logo) do |v|
75
+ v.process!(:original)
76
+ v.process!(:thumb) { |j| j.thumb!("16x16") }
77
+ end
78
+
79
+ model.picture_meta_data.must_equal({:original=>{:width=>216, :height=>63, :uid=>"original-apotomo.png"}, :thumb=>{:width=>16, :height=>5, :uid=>"thumb-apotomo.png"}})
80
+
81
+
82
+ model.picture do |v|
83
+ v.reprocess!(:thumb, "1") { |j| j.thumb!("8x8") }
84
+ end
85
+
86
+ model.picture_meta_data.class.must_equal Hash
87
+ model.picture_meta_data.must_equal({:original=>{:width=>216, :height=>63, :uid=>"original-apotomo.png"}, :thumb=>{:width=>8, :height=>2, :uid=>"thumb-apotomo-1.png"}})
88
+
89
+ model.picture do |v|
90
+ v.delete!(:thumb)
91
+ end
92
+
93
+ model.picture_meta_data.must_equal({:original=>{:width=>216, :height=>63, :uid=>"original-apotomo.png"}})
94
+ end
95
+
63
96
  # passing options from image(file, {..}) to the Attachment.
64
97
  class ImageWithAttachment < OpenStruct
65
98
  include Paperdragon::Model
@@ -75,9 +108,10 @@ class PaperdragonModelTest < MiniTest::Spec
75
108
  end
76
109
 
77
110
  processable :image, Attachment
111
+ processable :picture, Attachment
78
112
  end
79
113
 
80
- it do
114
+ it "image" do
81
115
  model = ImageWithAttachment.new
82
116
  model.image(logo, :path => "/") do |v|
83
117
  v.process!(:original)
@@ -92,6 +126,22 @@ class PaperdragonModelTest < MiniTest::Spec
92
126
 
93
127
  model.image_meta_data.must_equal({:original=>{:width=>8, :height=>2, :uid=>"{:new=>true, :model=>#<PaperdragonModelTest::ImageWithAttachment image_meta_data={:original=>{:width=>216, :height=>63, :uid=>\"{:path=>\\\"/\\\", :model=>_<PaperdragonModelTest::ImageWithAttachment>}\"}}>}"}})
94
128
  end
129
+
130
+ it "picture" do
131
+ model = ImageWithAttachment.new
132
+ model.picture(logo, :path => "/") do |v|
133
+ v.process!(:original)
134
+ end
135
+
136
+ # this assures that both :model and :path (see above) are passed through.
137
+ model.picture_meta_data.must_equal({:original=>{:width=>216, :height=>63, :uid=>"{:path=>\"/\", :model=>_<PaperdragonModelTest::ImageWithAttachment>}"}})
138
+
139
+ model.picture(nil, :new => true) do |v|
140
+ v.reprocess!(:original, "1") { |j| j.thumb!("8x8") }
141
+ end
142
+
143
+ model.picture_meta_data.must_equal({:original=>{:width=>8, :height=>2, :uid=>"{:new=>true, :model=>#<PaperdragonModelTest::ImageWithAttachment picture_meta_data={:original=>{:width=>216, :height=>63, :uid=>\"{:path=>\\\"/\\\", :model=>_<PaperdragonModelTest::ImageWithAttachment>}\"}}>}"}})
144
+ end
95
145
  end
96
146
 
97
147
 
@@ -122,8 +172,33 @@ class ModelWriterTest < MiniTest::Spec
122
172
  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"}})
123
173
  end
124
174
 
125
- end
175
+ # Using another name
176
+ class Picture < OpenStruct
177
+ extend Paperdragon::Model::Writer
178
+ processable_writer :picture
179
+ end
126
180
 
181
+ # process with #image{}
182
+ let (:logo) { Pathname("test/fixtures/apotomo.png") }
183
+
184
+ it do
185
+ model = Picture.new
186
+ model.picture!(logo) do |v|
187
+ v.process!(:original)
188
+ v.process!(:thumb) { |j| j.thumb!("16x16") }
189
+ end
190
+
191
+ model.picture_meta_data.must_equal({:original=>{:width=>216, :height=>63, :uid=>"original-apotomo.png"}, :thumb=>{:width=>16, :height=>5, :uid=>"thumb-apotomo.png"}})
192
+
193
+
194
+ model.picture! do |v|
195
+ v.reprocess!(:thumb, "1") { |j| j.thumb!("8x8") }
196
+ end
197
+
198
+ model.picture_meta_data.class.must_equal Hash
199
+ model.picture_meta_data.must_equal({:original=>{:width=>216, :height=>63, :uid=>"original-apotomo.png"}, :thumb=>{:width=>8, :height=>2, :uid=>"thumb-apotomo-1.png"}})
200
+ end
201
+ end
127
202
 
128
203
  class ModelReaderTest < MiniTest::Spec
129
204
  class Image < OpenStruct
@@ -132,4 +207,12 @@ class ModelReaderTest < MiniTest::Spec
132
207
  end
133
208
 
134
209
  it { Image.new(:image_meta_data => {:thumb => {:uid => "Avatar-thumb"}}).image[:thumb].url.must_equal "/paperdragon/Avatar-thumb" }
210
+
211
+ # Using another name
212
+ class Image < OpenStruct
213
+ extend Paperdragon::Model::Reader
214
+ processable_reader :picture
215
+ end
216
+
217
+ it { Image.new(:picture_meta_data => {:thumb => {:uid => "Avatar-thumb"}}).picture[:thumb].url.must_equal "/paperdragon/Avatar-thumb" }
135
218
  end
@@ -37,21 +37,47 @@ class PaperclipModelTest < MiniTest::Spec
37
37
  end
38
38
  end
39
39
 
40
+ class PictureAttachment < Paperdragon::Attachment
41
+ self.file_class = Photo
42
+
43
+ def exists?
44
+ "Of course it's a Picture!"
45
+ end
46
+ end
47
+
40
48
  include Paperdragon::Paperclip::Model
41
49
  processable :image, Attachment
50
+ processable :picture, PictureAttachment
42
51
 
43
52
 
44
53
  def image_meta_data
45
54
  {:thumb => {:uid => "Avatar-thumb"}}
46
55
  end
56
+
57
+ def picture_meta_data
58
+ {:thumb => {:uid => "Picture-thumb"}}
59
+ end
60
+ end
61
+
62
+ describe "image" do
63
+ # old paperclip style
64
+ it { Avatar.new.image.url(:thumb).must_equal "/paperdragon/Avatar-thumb" }
65
+
66
+ # paperdragon style
67
+ it { Avatar.new.image[:thumb].url.must_equal "/paperdragon/Avatar-thumb" }
68
+
69
+ # delegates all unknown methods back to Attachment.
70
+ it { Avatar.new.image.exists?.must_equal "Of course!" }
47
71
  end
48
72
 
49
- # old paperclip style
50
- it { Avatar.new.image.url(:thumb).must_equal "/paperdragon/Avatar-thumb" }
73
+ describe "picture" do
74
+ # old paperclip style
75
+ it { Avatar.new.picture.url(:thumb).must_equal "/paperdragon/Picture-thumb" }
51
76
 
52
- # paperdragon style
53
- it { Avatar.new.image[:thumb].url.must_equal "/paperdragon/Avatar-thumb" }
77
+ # paperdragon style
78
+ it { Avatar.new.picture[:thumb].url.must_equal "/paperdragon/Picture-thumb" }
54
79
 
55
- # delegates all unknown methods back to Attachment.
56
- it { Avatar.new.image.exists?.must_equal "Of course!" }
80
+ # delegates all unknown methods back to Attachment.
81
+ it { Avatar.new.picture.exists?.must_equal "Of course it's a Picture!" }
82
+ end
57
83
  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.10
4
+ version: 0.0.11
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-11-19 00:00:00.000000000 Z
11
+ date: 2015-12-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dragonfly