shrine 3.0.0.rc → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of shrine might be problematic. Click here for more details.

Files changed (167) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +10 -66
  3. data/README.md +39 -1061
  4. data/doc/advantages.md +151 -148
  5. data/doc/attacher.md +12 -30
  6. data/doc/carrierwave.md +150 -115
  7. data/doc/changing_derivatives.md +5 -11
  8. data/doc/changing_location.md +8 -5
  9. data/doc/changing_storage.md +5 -2
  10. data/doc/creating_persistence_plugins.md +9 -6
  11. data/doc/creating_plugins.md +42 -22
  12. data/doc/creating_storages.md +4 -1
  13. data/doc/design.md +7 -5
  14. data/doc/direct_s3.md +9 -4
  15. data/doc/external/articles.md +50 -0
  16. data/doc/external/extensions.md +46 -0
  17. data/doc/external/misc.md +17 -0
  18. data/doc/getting_started.md +1038 -0
  19. data/doc/metadata.md +5 -3
  20. data/doc/multiple_files.md +55 -29
  21. data/doc/paperclip.md +206 -163
  22. data/doc/plugins/activerecord.md +26 -6
  23. data/doc/plugins/add_metadata.md +4 -2
  24. data/doc/plugins/atomic_helpers.md +4 -2
  25. data/doc/plugins/backgrounding.md +83 -44
  26. data/doc/plugins/cached_attachment_data.md +4 -2
  27. data/doc/plugins/column.md +4 -2
  28. data/doc/plugins/data_uri.md +10 -6
  29. data/doc/plugins/default_storage.md +5 -3
  30. data/doc/plugins/default_url.md +4 -2
  31. data/doc/plugins/delete_raw.md +4 -2
  32. data/doc/plugins/derivation_endpoint.md +63 -39
  33. data/doc/plugins/derivatives.md +13 -50
  34. data/doc/plugins/determine_mime_type.md +6 -4
  35. data/doc/plugins/download_endpoint.md +6 -3
  36. data/doc/plugins/dynamic_storage.md +4 -2
  37. data/doc/plugins/entity.md +6 -4
  38. data/doc/plugins/form_assign.md +4 -2
  39. data/doc/plugins/included.md +4 -2
  40. data/doc/plugins/infer_extension.md +6 -4
  41. data/doc/plugins/instrumentation.md +5 -3
  42. data/doc/plugins/keep_files.md +9 -2
  43. data/doc/plugins/metadata_attributes.md +5 -3
  44. data/doc/plugins/mirroring.md +4 -2
  45. data/doc/plugins/model.md +6 -4
  46. data/doc/plugins/module_include.md +4 -2
  47. data/doc/plugins/multi_cache.md +4 -2
  48. data/doc/plugins/persistence.md +5 -3
  49. data/doc/plugins/presign_endpoint.md +6 -2
  50. data/doc/plugins/pretty_location.md +5 -3
  51. data/doc/plugins/processing.md +4 -2
  52. data/doc/plugins/rack_file.md +8 -2
  53. data/doc/plugins/rack_response.md +6 -2
  54. data/doc/plugins/recache.md +4 -2
  55. data/doc/plugins/refresh_metadata.md +5 -3
  56. data/doc/plugins/remote_url.md +26 -5
  57. data/doc/plugins/remove_attachment.md +4 -2
  58. data/doc/plugins/remove_invalid.md +10 -2
  59. data/doc/plugins/restore_cached_data.md +9 -3
  60. data/doc/plugins/sequel.md +26 -6
  61. data/doc/plugins/signature.md +6 -4
  62. data/doc/plugins/store_dimensions.md +6 -4
  63. data/doc/plugins/tempfile.md +4 -2
  64. data/doc/plugins/upload_endpoint.md +6 -2
  65. data/doc/plugins/upload_options.md +6 -4
  66. data/doc/plugins/url_options.md +4 -2
  67. data/doc/plugins/validation.md +7 -3
  68. data/doc/plugins/validation_helpers.md +13 -10
  69. data/doc/plugins/versions.md +4 -8
  70. data/doc/processing.md +27 -9
  71. data/doc/refile.md +119 -127
  72. data/doc/release_notes/1.0.0.md +4 -0
  73. data/doc/release_notes/1.1.0.md +4 -0
  74. data/doc/release_notes/1.2.0.md +4 -0
  75. data/doc/release_notes/1.3.0.md +4 -0
  76. data/doc/release_notes/1.4.0.md +4 -0
  77. data/doc/release_notes/1.4.1.md +4 -0
  78. data/doc/release_notes/1.4.2.md +4 -0
  79. data/doc/release_notes/2.0.0.md +4 -0
  80. data/doc/release_notes/2.0.1.md +4 -0
  81. data/doc/release_notes/2.1.0.md +4 -0
  82. data/doc/release_notes/2.1.1.md +4 -0
  83. data/doc/release_notes/2.10.0.md +4 -0
  84. data/doc/release_notes/2.10.1.md +4 -0
  85. data/doc/release_notes/2.11.0.md +4 -0
  86. data/doc/release_notes/2.12.0.md +4 -0
  87. data/doc/release_notes/2.13.0.md +4 -0
  88. data/doc/release_notes/2.14.0.md +5 -1
  89. data/doc/release_notes/2.15.0.md +10 -6
  90. data/doc/release_notes/2.16.0.md +4 -0
  91. data/doc/release_notes/2.17.0.md +4 -0
  92. data/doc/release_notes/2.18.0.md +4 -0
  93. data/doc/release_notes/2.19.0.md +7 -4
  94. data/doc/release_notes/2.2.0.md +4 -0
  95. data/doc/release_notes/2.3.0.md +4 -0
  96. data/doc/release_notes/2.3.1.md +4 -0
  97. data/doc/release_notes/2.4.0.md +4 -0
  98. data/doc/release_notes/2.4.1.md +4 -0
  99. data/doc/release_notes/2.5.0.md +4 -0
  100. data/doc/release_notes/2.6.0.md +4 -0
  101. data/doc/release_notes/2.6.1.md +4 -0
  102. data/doc/release_notes/2.7.0.md +4 -0
  103. data/doc/release_notes/2.8.0.md +4 -0
  104. data/doc/release_notes/2.9.0.md +4 -0
  105. data/doc/release_notes/3.0.0.md +120 -38
  106. data/doc/retrieving_uploads.md +4 -1
  107. data/doc/securing_uploads.md +4 -1
  108. data/doc/storage/file_system.md +12 -4
  109. data/doc/storage/s3.md +4 -2
  110. data/doc/testing.md +27 -41
  111. data/doc/upgrading_to_3.md +105 -26
  112. data/doc/validation.md +8 -6
  113. data/lib/shrine/attacher.rb +2 -2
  114. data/lib/shrine/attachment.rb +7 -10
  115. data/lib/shrine/plugins/activerecord.rb +10 -10
  116. data/lib/shrine/plugins/add_metadata.rb +1 -3
  117. data/lib/shrine/plugins/atomic_helpers.rb +6 -8
  118. data/lib/shrine/plugins/backgrounding.rb +4 -6
  119. data/lib/shrine/plugins/cached_attachment_data.rb +1 -3
  120. data/lib/shrine/plugins/column.rb +2 -4
  121. data/lib/shrine/plugins/data_uri.rb +1 -3
  122. data/lib/shrine/plugins/default_storage.rb +1 -3
  123. data/lib/shrine/plugins/default_url.rb +1 -3
  124. data/lib/shrine/plugins/delete_raw.rb +1 -3
  125. data/lib/shrine/plugins/derivation_endpoint.rb +3 -4
  126. data/lib/shrine/plugins/derivatives.rb +2 -4
  127. data/lib/shrine/plugins/determine_mime_type.rb +1 -3
  128. data/lib/shrine/plugins/download_endpoint.rb +1 -3
  129. data/lib/shrine/plugins/dynamic_storage.rb +1 -3
  130. data/lib/shrine/plugins/entity.rb +25 -9
  131. data/lib/shrine/plugins/form_assign.rb +1 -3
  132. data/lib/shrine/plugins/included.rb +1 -3
  133. data/lib/shrine/plugins/infer_extension.rb +1 -3
  134. data/lib/shrine/plugins/instrumentation.rb +1 -3
  135. data/lib/shrine/plugins/keep_files.rb +1 -3
  136. data/lib/shrine/plugins/metadata_attributes.rb +1 -3
  137. data/lib/shrine/plugins/mirroring.rb +2 -1
  138. data/lib/shrine/plugins/model.rb +2 -4
  139. data/lib/shrine/plugins/module_include.rb +1 -3
  140. data/lib/shrine/plugins/multi_cache.rb +3 -3
  141. data/lib/shrine/plugins/presign_endpoint.rb +1 -3
  142. data/lib/shrine/plugins/pretty_location.rb +1 -3
  143. data/lib/shrine/plugins/processing.rb +1 -3
  144. data/lib/shrine/plugins/rack_file.rb +1 -3
  145. data/lib/shrine/plugins/rack_response.rb +1 -3
  146. data/lib/shrine/plugins/recache.rb +1 -3
  147. data/lib/shrine/plugins/refresh_metadata.rb +1 -3
  148. data/lib/shrine/plugins/remote_url.rb +1 -3
  149. data/lib/shrine/plugins/remove_attachment.rb +1 -3
  150. data/lib/shrine/plugins/remove_invalid.rb +1 -3
  151. data/lib/shrine/plugins/restore_cached_data.rb +1 -3
  152. data/lib/shrine/plugins/sequel.rb +10 -12
  153. data/lib/shrine/plugins/signature.rb +1 -3
  154. data/lib/shrine/plugins/store_dimensions.rb +1 -3
  155. data/lib/shrine/plugins/tempfile.rb +1 -3
  156. data/lib/shrine/plugins/upload_endpoint.rb +1 -3
  157. data/lib/shrine/plugins/upload_options.rb +1 -3
  158. data/lib/shrine/plugins/url_options.rb +1 -3
  159. data/lib/shrine/plugins/validation.rb +1 -3
  160. data/lib/shrine/plugins/validation_helpers.rb +1 -3
  161. data/lib/shrine/plugins/versions.rb +1 -3
  162. data/lib/shrine/storage/file_system.rb +1 -1
  163. data/lib/shrine/storage/linter.rb +1 -1
  164. data/lib/shrine/storage/memory.rb +2 -1
  165. data/lib/shrine/storage/s3.rb +3 -3
  166. data/lib/shrine/version.rb +1 -1
  167. metadata +8 -4
@@ -1,10 +1,12 @@
1
- # Active Record
1
+ ---
2
+ title: Active Record
3
+ ---
2
4
 
3
5
  The [`activerecord`][activerecord] plugin adds [Active Record] integration to
4
6
  the attachment interface. It is built on top of the [`model`][model] plugin.
5
7
 
6
8
  ```rb
7
- plugin :activerecord
9
+ Shrine.plugin :activerecord
8
10
  ```
9
11
 
10
12
  ## Attachment
@@ -78,6 +80,24 @@ Active Record currently has a [bug with transaction callbacks], so if you have
78
80
  any "after commit" callbacks, make sure to include Shrine's attachment module
79
81
  *after* they have all been defined.
80
82
 
83
+ #### Overriding callbacks
84
+
85
+ You can override any of the following attacher methods to modify callback
86
+ behaviour:
87
+
88
+ * `Attacher#activerecord_before_save`
89
+ * `Attacher#activerecord_after_save`
90
+ * `Attacher#activerecord_after_destroy`
91
+
92
+ ```rb
93
+ class Shrine::Attacher
94
+ def activerecord_after_save
95
+ super
96
+ # ...
97
+ end
98
+ end
99
+ ```
100
+
81
101
  #### Skipping Callbacks
82
102
 
83
103
  If you don't want the attachment module to add any callbacks to your model, you
@@ -195,10 +215,10 @@ The following persistence methods are added to `Shrine::Attacher`:
195
215
 
196
216
  See [persistence] docs for more details.
197
217
 
198
- [activerecord]: /lib/shrine/plugins/activerecord.rb
218
+ [activerecord]: https://github.com/shrinerb/shrine/blob/master/lib/shrine/plugins/activerecord.rb
199
219
  [Active Record]: https://guides.rubyonrails.org/active_record_basics.html
200
- [model]: /doc/plugins/model.md#readme
220
+ [model]: https://shrinerb.com/docs/plugins/model
201
221
  [callbacks]: https://guides.rubyonrails.org/active_record_callbacks.html
202
222
  [bug with transaction callbacks]: https://github.com/rails/rails/issues/14493
203
- [validation]: /doc/plugins/validation.md#readme
204
- [persistence]: /doc/plugins/persistence.md#readme
223
+ [validation]: https://shrinerb.com/docs/plugins/validation
224
+ [persistence]: https://shrinerb.com/docs/plugins/persistence
@@ -1,4 +1,6 @@
1
- # Add Metadata
1
+ ---
2
+ title: Add Metadata
3
+ ---
2
4
 
3
5
  The [`add_metadata`][add_metadata] plugin provides a convenient method for
4
6
  extracting and adding custom metadata values.
@@ -114,4 +116,4 @@ add_metadata :bar do |io, metadata:, **|
114
116
  end
115
117
  ```
116
118
 
117
- [add_metadata]: /lib/shrine/plugins/add_metadata.rb
119
+ [add_metadata]: https://github.com/shrinerb/shrine/blob/master/lib/shrine/plugins/add_metadata.rb
@@ -1,4 +1,6 @@
1
- # Atomic Helpers
1
+ ---
2
+ title: Atomic Helpers
3
+ ---
2
4
 
3
5
  The [`atomic_helpers`][atomic_helpers] plugin provides API for retrieving and
4
6
  persisting attachments in a concurrency-safe way, which is useful when using
@@ -174,4 +176,4 @@ attacher.abstract_atomic_persist(**options) do |reloaded_attacher|
174
176
  end
175
177
  ```
176
178
 
177
- [atomic_helpers]: /lib/shrine/plugins/atomic_helpers.rb
179
+ [atomic_helpers]: https://github.com/shrinerb/shrine/blob/master/lib/shrine/plugins/atomic_helpers.rb
@@ -1,4 +1,6 @@
1
- # Backgrounding
1
+ ---
2
+ title: Backgrounding
3
+ ---
2
4
 
3
5
  The [`backgrounding`][backgrounding] plugin enables you to move promoting and
4
6
  deleting of files into background jobs. This is especially useful if you're
@@ -8,20 +10,10 @@ processing [derivatives] and storing files to a remote storage service.
8
10
  Shrine.plugin :backgrounding # load the plugin globally
9
11
  ```
10
12
 
11
- The plugin provides `Attacher.promote_block` and `Attacher.destroy_block`
12
- methods, which allow you to register blocks that will get executed in place of
13
- synchronous promotion and deletion. Inside them you can spawn your background
14
- jobs:
13
+ ## Setup
14
+
15
+ Define background jobs that will promote and destroy attachments:
15
16
 
16
- ```rb
17
- # register backgrounding blocks for all uploaders
18
- Shrine::Attacher.promote_block do
19
- PromoteJob.perform_async(self.class.name, record.class.name, record.id, name, file_data)
20
- end
21
- Shrine::Attacher.destroy_block do
22
- DestroyJob.perform_async(self.class.name, data)
23
- end
24
- ```
25
17
  ```rb
26
18
  class PromoteJob
27
19
  include Sidekiq::Worker
@@ -50,12 +42,21 @@ class DestroyJob
50
42
  end
51
43
  ```
52
44
 
53
- If you don't want to apply backgrounding for all uploaders, you can register
54
- backgrounding blocks only for a specific uploader:
45
+ Then, in your initializer, you can configure all uploaders to use these jobs:
46
+
47
+ ```rb
48
+ Shrine::Attacher.promote_block do
49
+ PromoteJob.perform_async(self.class.name, record.class.name, record.id, name, file_data)
50
+ end
51
+ Shrine::Attacher.destroy_block do
52
+ DestroyJob.perform_async(self.class.name, data)
53
+ end
54
+ ```
55
+
56
+ Alternatively, you can setup backgrounding only for specific uploaders:
55
57
 
56
58
  ```rb
57
59
  class MyUploader < Shrine
58
- # register backgrounding blocks only for this uploader
59
60
  Attacher.promote_block do
60
61
  PromoteJob.perform_async(self.class.name, record.class.name, record.id, name, file_data)
61
62
  end
@@ -65,20 +66,11 @@ class MyUploader < Shrine
65
66
  end
66
67
  ```
67
68
 
68
- Backgrounding will automatically get triggered as part of your attachment flow
69
- if you're using `Shrine::Attachment` with a persistence plugin such as
70
- `activerecord` or `sequel`:
71
-
72
- ```rb
73
- photo = Photo.new
74
- photo.image = file
75
- photo.save # spawns promote job
76
- photo.destroy # spawns destroy job
77
- ```
69
+ ## How it works
78
70
 
79
- In terms of `Shrine::Attacher`, the background jobs are spawned on
80
- `Attacher#promote_cached` (called on `Attacher#finalize`) and
81
- `Attacher#destroy_attached`:
71
+ If backgrounding blocks are registered, they will be automatically called on
72
+ `Attacher#promote_cached` and `Attacher#destroy_previous` (called by
73
+ `Attacher#finalize`), and `Attacher#destroy_attached`.
82
74
 
83
75
  ```rb
84
76
  attacher.assign(file)
@@ -86,23 +78,30 @@ attacher.finalize # spawns promote job
86
78
  attacher.destroy_attached # spawns destroy job
87
79
  ```
88
80
 
89
- ## Promotion
81
+ These methods are automatically called as part of the attachment flow if you're
82
+ using `Shrine::Attachment` with a persistence plugin such as `activerecord` or
83
+ `sequel`.
90
84
 
91
- While background deletion acts only on file data, background promotion is more
92
- complex as it deals with persistence and concurrency safety:
85
+ ```rb
86
+ photo = Photo.new
87
+ photo.image = file
88
+ photo.save # spawns promote job
89
+ photo.destroy # spawns destroy job
90
+ ```
91
+
92
+ ### Atomic promotion
93
+
94
+ Inside the promote job, we use `Attacher.retrieve` and
95
+ `Attacher#atomic_promote` for concurrency safety. These methods are provided
96
+ by the [`atomic_helpers`][atomic_helpers] plugin, which is loaded automatically
97
+ by your persistence plugin (`activerecord`, `sequel`).
93
98
 
94
99
  ```rb
95
100
  attacher = Shrine::Attacher.retrieve(model: record, name: name, file: file_data)
96
101
  attacher.atomic_promote
97
102
  ```
98
103
 
99
- The `Attacher.retrieve` and `Attacher#atomic_promote` methods are provided by
100
- the [`atomic_helpers`][atomic_helpers] plugin, which is automatically loaded by
101
- your persistence plugin (`activerecord`, `sequel`). They add concurrency safety
102
- by verifying that the attachment hasn't changed on the outside before or after
103
- promotion.
104
-
105
- When we remove the concurrency safety, promotion would look like this:
104
+ Without concurrency safety, promotion would look like this:
106
105
 
107
106
  ```rb
108
107
  attacher = record.send(:"#{name}_attacher")
@@ -110,7 +109,7 @@ attacher.promote
110
109
  attacher.persist
111
110
  ```
112
111
 
113
- ## Backgrounding blocks
112
+ ## Registering backgrounding blocks
114
113
 
115
114
  The blocks registered by `Attacher.promote_block` and `Attacher#destroy_block`
116
115
  are by default evaluated in context of a `Shrine::Attacher` instance. You can
@@ -154,6 +153,46 @@ photo.image = file
154
153
  photo.save # executes the promote block above
155
154
  ```
156
155
 
157
- [backgrounding]: /lib/shrine/plugins/backgrounding.rb
158
- [derivatives]: /doc/plugins/derivatives.md#readme
159
- [atomic_helpers]: /doc/plugins/atomic_helpers.md#readme
156
+ ## Calling backgrounding blocks
157
+
158
+ If you want to call backgrounding blocks directly, you can do that by calling
159
+ `Attacher#promote_background` and `Attacher#destroy_background`.
160
+
161
+ ```rb
162
+ attacher.promote_background # calls promote block directly
163
+ attacher.destroy_background # calls destroy block directly
164
+ ```
165
+
166
+ Any options passed to these methods will be forwarded to the background block:
167
+
168
+ ```rb
169
+ attacher.promote_background(foo: "bar")
170
+ ```
171
+ ```rb
172
+ # with instance eval
173
+ Shrine::Attacher.promote_block do |**options|
174
+ options #=> { foo: "bar" }
175
+ end
176
+
177
+ # without instance eval
178
+ Shrine::Attacher.promote_block do |attacher, **options|
179
+ options #=> { foo: "bar" }
180
+ end
181
+ ```
182
+
183
+ ## Disabling backgrounding
184
+
185
+ If you've registered backgrounding blocks, but want to temporarily disable them
186
+ and make the execution synchronous, you can override them on the attacher level
187
+ and call the default behaviour:
188
+
189
+ ```rb
190
+ photo.image_attacher.promote_block(&:promote)
191
+ photo.image_attacher.destroy_block(&:destroy)
192
+
193
+ # ... now promotion and deletion will be synchronous ...
194
+ ```
195
+
196
+ [backgrounding]: https://github.com/shrinerb/shrine/blob/master/lib/shrine/plugins/backgrounding.rb
197
+ [derivatives]: https://shrinerb.com/docs/plugins/derivatives
198
+ [atomic_helpers]: https://shrinerb.com/docs/plugins/atomic_helpers
@@ -1,4 +1,6 @@
1
- # Cached Attachment Data
1
+ ---
2
+ title: Cached Attachment Data
3
+ ---
2
4
 
3
5
  The [`cached_attachment_data`][cached_attachment_data] plugin adds the ability
4
6
  to retain the cached file across form redisplays, which means the file doesn't
@@ -22,4 +24,4 @@ This method delegates to `Attacher#cached_data`:
22
24
  attacher.cached_data #=> '{"id":"38k25.jpg","storage":"cache","metadata":{...}}'
23
25
  ```
24
26
 
25
- [cached_attachment_data]: /lib/shrine/plugins/cached_attachment_data.rb
27
+ [cached_attachment_data]: https://github.com/shrinerb/shrine/blob/master/lib/shrine/plugins/cached_attachment_data.rb
@@ -1,4 +1,6 @@
1
- # Column
1
+ ---
2
+ title: Column
3
+ ---
2
4
 
3
5
  The [`column`][column] plugin provides interface for serializing and
4
6
  deserializing attachment data in format suitable for persisting in a database
@@ -87,4 +89,4 @@ Shrine::Attacher.new(column_serializer: Oj) # use custom serializer
87
89
  Shrine::Attacher.new(column_serializer: nil) # disable serialization
88
90
  ```
89
91
 
90
- [column]: /lib/shrine/plugins/column.rb
92
+ [column]: https://github.com/shrinerb/shrine/blob/master/lib/shrine/plugins/column.rb
@@ -1,4 +1,6 @@
1
- # Data URI
1
+ ---
2
+ title: Data URI
3
+ ---
2
4
 
3
5
  The [`data_uri`][data_uri] plugin enables you to upload files as [data URIs].
4
6
  This plugin is useful for example when using [HTML5 Canvas].
@@ -7,6 +9,8 @@ This plugin is useful for example when using [HTML5 Canvas].
7
9
  plugin :data_uri
8
10
  ```
9
11
 
12
+ ## Usage
13
+
10
14
  The plugin will add the `#<name>_data_uri` writer to your model, which parses
11
15
  the given data URI string and uploads it to temporary storage:
12
16
 
@@ -62,7 +66,7 @@ do that with `Shrine.data_uri`. If the data URI cannot be parsed, a
62
66
  `Shrine::Plugins::DataUri::ParseError` will be raised.
63
67
 
64
68
  ```rb
65
- # or YourUploader.data_uri("...")
69
+ # or YourUploader.data_uri(...)
66
70
  io = Shrine.data_uri("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUA")
67
71
  io.content_type #=> "image/png"
68
72
  io.size #=> 21
@@ -87,7 +91,7 @@ io = Shrine.data_uri("data:,content", filename: "foo.txt")
87
91
  io.original_filename #=> "foo.txt"
88
92
  ```
89
93
 
90
- ### Generating data URI
94
+ ## Generating data URI
91
95
 
92
96
  This plugin also adds `UploadedFile#data_uri` method, which returns a
93
97
  base64-encoded data URI of the file content, and `UploadedFile#base64`, which
@@ -119,7 +123,7 @@ payload:
119
123
 
120
124
  A default log subscriber is added as well which logs these events:
121
125
 
122
- ```
126
+ ```plaintext
123
127
  Data URI (5ms) – {:uploader=>Shrine}
124
128
  ```
125
129
 
@@ -130,7 +134,7 @@ plugin :data_uri, log_subscriber: -> (event) {
130
134
  Shrine.logger.info JSON.generate(name: event.name, duration: event.duration, uploader: event[:uploader])
131
135
  }
132
136
  ```
133
- ```
137
+ ```plaintext
134
138
  {"name":"data_uri","duration":5,"uploader":"Shrine"}
135
139
  ```
136
140
 
@@ -140,6 +144,6 @@ Or disable logging altogether:
140
144
  plugin :data_uri, log_subscriber: nil
141
145
  ```
142
146
 
143
- [data_uri]: /lib/shrine/plugins/data_uri.rb
147
+ [data_uri]: https://github.com/shrinerb/shrine/blob/master/lib/shrine/plugins/data_uri.rb
144
148
  [data URIs]: https://tools.ietf.org/html/rfc2397
145
149
  [HTML5 Canvas]: https://developer.mozilla.org/en-US/docs/Web/API/Canvas_API
@@ -1,4 +1,6 @@
1
- # Default Storage
1
+ ---
2
+ title: Default Storage
3
+ ---
2
4
 
3
5
  The [`default_storage`][default_storage] plugin allows you to change the
4
6
  default temporary and permanent storage a `Shrine::Attacher` object will use
@@ -39,5 +41,5 @@ Attacher.default_store { :other_store }
39
41
  The dynamic block is useful in combination with the
40
42
  [`dynamic_storage`][dynamic_storage] plugin.
41
43
 
42
- [default_storage]: /lib/shrine/plugins/default_storage.rb
43
- [dynamic_storage]: /doc/plugins/dynamic_storage.md#readme
44
+ [default_storage]: https://github.com/shrinerb/shrine/blob/master/lib/shrine/plugins/default_storage.rb
45
+ [dynamic_storage]: https://shrinerb.com/docs/plugins/dynamic_storage
@@ -1,4 +1,6 @@
1
- # Default URL
1
+ ---
2
+ title: Default URL
3
+ ---
2
4
 
3
5
  The [`default_url`][default_url] plugin allows setting the URL which will be
4
6
  returned when there is no attached file.
@@ -56,4 +58,4 @@ plugin :default_url, host: "https://example.com"
56
58
  attacher.url #=> "https://example.com/avatar/missing.jpg"
57
59
  ```
58
60
 
59
- [default_url]: /lib/shrine/plugins/default_url.rb
61
+ [default_url]: https://github.com/shrinerb/shrine/blob/master/lib/shrine/plugins/default_url.rb
@@ -1,4 +1,6 @@
1
- # Delete Raw
1
+ ---
2
+ title: Delete Raw
3
+ ---
2
4
 
3
5
  The [`delete_raw`][delete_raw] plugin will automatically delete raw files that
4
6
  have been uploaded. This is especially useful when doing processing, to ensure
@@ -22,4 +24,4 @@ to the uploader:
22
24
  uploader.upload(file, delete: false)
23
25
  ```
24
26
 
25
- [delete_raw]: /lib/shrine/plugins/delete_raw.rb
27
+ [delete_raw]: https://github.com/shrinerb/shrine/blob/master/lib/shrine/plugins/delete_raw.rb
@@ -1,35 +1,12 @@
1
- # Derivation Endpoint
1
+ ---
2
+ title: Derivation Endpoint
3
+ ---
2
4
 
3
5
  The [`derivation_endpoint`][derivation_endpoint] plugin provides a Rack app for
4
6
  dynamically processing uploaded files on request. This allows you to create
5
7
  URLs to files that might not have been generated yet, and have the endpoint
6
8
  process them on-the-fly.
7
9
 
8
- ## Contents
9
-
10
- * [Quick start](#quick-start)
11
- * [How it works](#how-it-works)
12
- - [Performance](#performance)
13
- * [Derivation response](#derivation-response)
14
- * [Dynamic settings](#dynamic-settings)
15
- * [Host](#host)
16
- * [Prefix](#prefix)
17
- * [Expiration](#expiration)
18
- * [Response headers](#response-headers)
19
- - [Content Type](#content-type)
20
- - [Content Disposition](#content-disposition)
21
- - [Cache Control](#cache-control)
22
- * [Uploading](#uploading)
23
- - [Redirecting](#redirecting)
24
- - [Deleting derivatives](#deleting-derivatives)
25
- * [Cache busting](#cache-busting)
26
- * [Accessing source file](#accessing-source-file)
27
- * [Downloading](#downloading)
28
- - [Skipping download](#skipping-download)
29
- * [Derivation API](#derivation-api)
30
- * [Plugin Options](#plugin-options)
31
- * [Instrumentation](#instrumentation)
32
-
33
10
  ## Quick start
34
11
 
35
12
  We first load the plugin, providing a secret key and a path prefix to where the
@@ -91,7 +68,7 @@ generates an URL consisting of the configured [path prefix](#prefix),
91
68
  derivation name and arguments, serialized uploaded file, and an URL signature
92
69
  generated using the configured secret key:
93
70
 
94
- ```
71
+ ```plaintext
95
72
  / derivations/image / thumbnail / 600/400 / eyJmZvbyIb3JhZ2UiOiJzdG9yZSJ9 ? signature=...
96
73
  └──── prefix ─────┘ └── name ──┘ └─ args ─┘ └─── serialized source file ───┘
97
74
  ```
@@ -434,6 +411,8 @@ fetch the original uploaded file, call the derivation block, upload the
434
411
  derivative to the storage, and serve the derivative. If the derivative does
435
412
  exist on checking, the endpoint will download the derivative and serve it.
436
413
 
414
+ ### Upload location
415
+
437
416
  The default upload location for derivatives is `<source id>/<name>-<args>`.
438
417
  This can be changed with the `:upload_location` option:
439
418
 
@@ -449,6 +428,8 @@ response won't know the appropriate `Content-Type` header value to set, and the
449
428
  generic `application/octet-stream` will be used. It's recommended to use the
450
429
  [`:type`](#content-type) option to set the appropriate `Content-Type` value.
451
430
 
431
+ ### Upload storage
432
+
452
433
  The target storage used is the same as for the source uploaded file. The
453
434
  `:upload_storage` option can be used to specify a different Shrine storage:
454
435
 
@@ -457,6 +438,8 @@ plugin :derivation_endpoint, upload: true,
457
438
  upload_storage: :thumbnail_storage
458
439
  ```
459
440
 
441
+ ### Upload options
442
+
460
443
  Additional storage-specific upload options can be passed via `:upload_options`:
461
444
 
462
445
  ```rb
@@ -464,6 +447,8 @@ plugin :derivation_endpoint, upload: true,
464
447
  upload_options: { acl: "public-read" }
465
448
  ```
466
449
 
450
+ ### Upload open options
451
+
467
452
  Additional storage-specific download options for the uploaded derivation result
468
453
  can be passed via `:upload_open_options`:
469
454
 
@@ -484,8 +469,7 @@ plugin :derivation_endpoint, upload: true,
484
469
  upload_redirect: true
485
470
  ```
486
471
 
487
- In that case additional storage-specific URL options can be passed in for the
488
- redirect URL:
472
+ Additional storage-specific URL options can be passed in for the redirect URL:
489
473
 
490
474
  ```rb
491
475
  plugin :derivation_endpoint, upload: true,
@@ -493,18 +477,58 @@ plugin :derivation_endpoint, upload: true,
493
477
  upload_redirect_url_options: { public: true }
494
478
  ```
495
479
 
496
- If you are using the local filesystem storage, then redirecting does not make
497
- sense.
480
+ Note that redirecting only makes sense if you're using remote storage services
481
+ such as AWS S3 or Google Cloud Storage.
498
482
 
499
483
  ### Deleting derivatives
500
484
 
501
485
  When the original attachment is deleted, its uploaded derivatives will not be
502
- automatically deleted, you will need to do the deletion manually. You can do
503
- that by calling `Shrine::Derivation#delete` for each derivation you're using:
486
+ automatically deleted, you will need to do the deletion manually. To ensure
487
+ this gets called both on destroying and replacing, you can add that code to
488
+ `Attacher#destroy`.
489
+
490
+ The easiest way is to delete the directory containing your derivatives:
491
+
492
+ ```rb
493
+ class ImageUploader < Shrine
494
+ class Attacher
495
+ def destroy(*args)
496
+ super
497
+
498
+ derivatives_directory = file.id
499
+ storage = store.storage
500
+
501
+ storage.delete_prefixed(derivatives_directory)
502
+ end
503
+ end
504
+ end
505
+ ```
506
+
507
+ This is under the assumption that your storage implements `#delete_prefixed`
508
+ and that you're using default [`:upload_location`](#upload-location).
509
+
510
+ Alternatively, you can delete each derivative individually using
511
+ `Derivation#delete`:
504
512
 
505
513
  ```rb
506
- # photo is the model and image is the file attachment
507
- photo.image.derivation(:thumbnail).delete
514
+ class ImageUploader < Shrine
515
+ DERIVATIONS = [
516
+ [:thumbnail, 800, 800],
517
+ [:thumbnail, 600, 400],
518
+ [:thumbnail, 400, 300],
519
+ ...
520
+ ]
521
+
522
+ class Attacher
523
+ def destroy(*args)
524
+ super
525
+
526
+ DERIVATIONS.each do |args|
527
+ file.derivation(*args).delete
528
+ end
529
+ end
530
+ end
531
+ end
508
532
  ```
509
533
 
510
534
  ## Cache busting
@@ -771,7 +795,7 @@ derivation.option(:upload_location)
771
795
  | `:download_options` | Additional options to pass when downloading the source uploaded file | `{}` |
772
796
  | `:expires_in` | Number of seconds after which the URL will not be available anymore | `nil` |
773
797
  | `:filename` | Filename the browser will assume when the derivative is downloaded to disk | `<name>-<args>-<source id basename>` |
774
- | `:host` | URL host to use when generated URLs | `nil` |
798
+ | `:host` | URL host to use when for URLs | `nil` |
775
799
  | `:metadata` | List of metadata keys the source uploaded file should include in the derivation block | `[]` |
776
800
  | `:prefix` | Path prefix added to the URLs | `nil` |
777
801
  | `:secret_key` | Key used to sign derivation URLs in order to prevent tampering | required |
@@ -806,7 +830,7 @@ following payload:
806
830
 
807
831
  A default log subscriber is added as well which logs these events:
808
832
 
809
- ```
833
+ ```plaintext
810
834
  Derivation (492ms) – {:name=>:thumbnail, :args=>[600, 600], :uploader=>Shrine}
811
835
  ```
812
836
 
@@ -822,7 +846,7 @@ plugin :derivation_endpoint, log_subscriber: -> (event) {
822
846
  )
823
847
  }
824
848
  ```
825
- ```
849
+ ```plaintext
826
850
  {"name":"derivation","duration":492,"name":"thumbnail","args":[600,600],"uploader":"Shrine"}
827
851
  ```
828
852
 
@@ -832,7 +856,7 @@ Or disable logging altogether:
832
856
  plugin :derivation_endpoint, log_subscriber: nil
833
857
  ```
834
858
 
835
- [derivation_endpoint]: /lib/shrine/plugins/derivation_endpoint.rb
859
+ [derivation_endpoint]: https://github.com/shrinerb/shrine/blob/master/lib/shrine/plugins/derivation_endpoint.rb
836
860
  [ImageProcessing]: https://github.com/janko/image_processing
837
861
  [`Content-Type`]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Type
838
862
  [`Content-Disposition`]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Disposition