shrine 2.19.3 → 3.6.0

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.
Files changed (211) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +523 -41
  3. data/LICENSE.txt +1 -1
  4. data/README.md +83 -979
  5. data/doc/advantages.md +231 -204
  6. data/doc/attacher.md +304 -153
  7. data/doc/carrierwave.md +297 -226
  8. data/doc/changing_derivatives.md +308 -0
  9. data/doc/changing_location.md +103 -21
  10. data/doc/changing_storage.md +110 -0
  11. data/doc/creating_persistence_plugins.md +132 -0
  12. data/doc/creating_plugins.md +43 -23
  13. data/doc/creating_storages.md +19 -5
  14. data/doc/design.md +147 -97
  15. data/doc/direct_s3.md +38 -28
  16. data/doc/external/articles.md +63 -0
  17. data/doc/external/extensions.md +53 -0
  18. data/doc/external/misc.md +32 -0
  19. data/doc/getting_started.md +1156 -0
  20. data/doc/metadata.md +190 -109
  21. data/doc/multiple_files.md +93 -30
  22. data/doc/paperclip.md +384 -262
  23. data/doc/plugins/activerecord.md +177 -46
  24. data/doc/plugins/add_metadata.md +139 -38
  25. data/doc/plugins/atomic_helpers.md +217 -0
  26. data/doc/plugins/backgrounding.md +156 -98
  27. data/doc/plugins/cached_attachment_data.md +7 -5
  28. data/doc/plugins/column.md +121 -0
  29. data/doc/plugins/data_uri.md +23 -22
  30. data/doc/plugins/default_storage.md +36 -10
  31. data/doc/plugins/default_url.md +30 -13
  32. data/doc/plugins/delete_raw.md +4 -2
  33. data/doc/plugins/derivation_endpoint.md +186 -101
  34. data/doc/plugins/derivatives.md +839 -0
  35. data/doc/plugins/determine_mime_type.md +4 -2
  36. data/doc/plugins/download_endpoint.md +64 -8
  37. data/doc/plugins/dynamic_storage.md +5 -3
  38. data/doc/plugins/entity.md +263 -0
  39. data/doc/plugins/form_assign.md +55 -0
  40. data/doc/plugins/included.md +31 -8
  41. data/doc/plugins/infer_extension.md +21 -10
  42. data/doc/plugins/instrumentation.md +38 -16
  43. data/doc/plugins/keep_files.md +16 -17
  44. data/doc/plugins/metadata_attributes.md +42 -13
  45. data/doc/plugins/mirroring.md +118 -0
  46. data/doc/plugins/model.md +210 -0
  47. data/doc/plugins/module_include.md +4 -2
  48. data/doc/plugins/multi_cache.md +24 -0
  49. data/doc/plugins/persistence.md +101 -0
  50. data/doc/plugins/presign_endpoint.md +9 -4
  51. data/doc/plugins/pretty_location.md +16 -3
  52. data/doc/plugins/processing.md +4 -2
  53. data/doc/plugins/rack_file.md +8 -2
  54. data/doc/plugins/rack_response.md +6 -2
  55. data/doc/plugins/recache.md +4 -2
  56. data/doc/plugins/refresh_metadata.md +49 -9
  57. data/doc/plugins/remote_url.md +84 -47
  58. data/doc/plugins/remove_attachment.md +27 -6
  59. data/doc/plugins/remove_invalid.md +21 -6
  60. data/doc/plugins/restore_cached_data.md +11 -3
  61. data/doc/plugins/sequel.md +159 -35
  62. data/doc/plugins/signature.md +16 -5
  63. data/doc/plugins/store_dimensions.md +14 -2
  64. data/doc/plugins/tempfile.md +4 -2
  65. data/doc/plugins/type_predicates.md +96 -0
  66. data/doc/plugins/upload_endpoint.md +13 -13
  67. data/doc/plugins/upload_options.md +6 -4
  68. data/doc/plugins/{default_url_options.md → url_options.md} +9 -7
  69. data/doc/plugins/validation.md +97 -0
  70. data/doc/plugins/validation_helpers.md +16 -13
  71. data/doc/plugins/versions.md +15 -19
  72. data/doc/processing.md +438 -221
  73. data/doc/refile.md +188 -170
  74. data/doc/release_notes/1.0.0.md +4 -0
  75. data/doc/release_notes/1.1.0.md +6 -2
  76. data/doc/release_notes/1.2.0.md +4 -0
  77. data/doc/release_notes/1.3.0.md +4 -0
  78. data/doc/release_notes/1.4.0.md +4 -0
  79. data/doc/release_notes/1.4.1.md +4 -0
  80. data/doc/release_notes/1.4.2.md +4 -0
  81. data/doc/release_notes/2.0.0.md +4 -0
  82. data/doc/release_notes/2.0.1.md +4 -0
  83. data/doc/release_notes/2.1.0.md +5 -1
  84. data/doc/release_notes/2.1.1.md +4 -0
  85. data/doc/release_notes/2.10.0.md +4 -0
  86. data/doc/release_notes/2.10.1.md +4 -0
  87. data/doc/release_notes/2.11.0.md +4 -0
  88. data/doc/release_notes/2.12.0.md +4 -0
  89. data/doc/release_notes/2.13.0.md +4 -0
  90. data/doc/release_notes/2.14.0.md +5 -1
  91. data/doc/release_notes/2.15.0.md +11 -7
  92. data/doc/release_notes/2.16.0.md +4 -0
  93. data/doc/release_notes/2.17.0.md +4 -0
  94. data/doc/release_notes/2.18.0.md +4 -0
  95. data/doc/release_notes/2.19.0.md +6 -3
  96. data/doc/release_notes/2.2.0.md +4 -0
  97. data/doc/release_notes/2.3.0.md +4 -0
  98. data/doc/release_notes/2.3.1.md +4 -0
  99. data/doc/release_notes/2.4.0.md +4 -0
  100. data/doc/release_notes/2.4.1.md +4 -0
  101. data/doc/release_notes/2.5.0.md +4 -0
  102. data/doc/release_notes/2.6.0.md +4 -0
  103. data/doc/release_notes/2.6.1.md +4 -0
  104. data/doc/release_notes/2.7.0.md +4 -0
  105. data/doc/release_notes/2.8.0.md +4 -0
  106. data/doc/release_notes/2.9.0.md +4 -0
  107. data/doc/release_notes/3.0.0.md +981 -0
  108. data/doc/release_notes/3.0.1.md +22 -0
  109. data/doc/release_notes/3.1.0.md +73 -0
  110. data/doc/release_notes/3.2.0.md +96 -0
  111. data/doc/release_notes/3.2.1.md +31 -0
  112. data/doc/release_notes/3.2.2.md +14 -0
  113. data/doc/release_notes/3.3.0.md +105 -0
  114. data/doc/release_notes/3.4.0.md +35 -0
  115. data/doc/release_notes/3.5.0.md +63 -0
  116. data/doc/release_notes/3.6.0.md +23 -0
  117. data/doc/retrieving_uploads.md +5 -2
  118. data/doc/securing_uploads.md +60 -37
  119. data/doc/storage/file_system.md +20 -3
  120. data/doc/storage/memory.md +19 -0
  121. data/doc/storage/s3.md +122 -78
  122. data/doc/testing.md +141 -133
  123. data/doc/upgrading_to_3.md +708 -0
  124. data/doc/validation.md +54 -90
  125. data/lib/shrine/attacher.rb +292 -169
  126. data/lib/shrine/attachment.rb +13 -46
  127. data/lib/shrine/plugins/_persistence.rb +93 -0
  128. data/lib/shrine/plugins/activerecord.rb +77 -34
  129. data/lib/shrine/plugins/add_metadata.rb +25 -17
  130. data/lib/shrine/plugins/atomic_helpers.rb +119 -0
  131. data/lib/shrine/plugins/backgrounding.rb +77 -113
  132. data/lib/shrine/plugins/cached_attachment_data.rb +6 -15
  133. data/lib/shrine/plugins/column.rb +102 -0
  134. data/lib/shrine/plugins/data_uri.rb +38 -36
  135. data/lib/shrine/plugins/default_storage.rb +45 -15
  136. data/lib/shrine/plugins/default_url.rb +12 -24
  137. data/lib/shrine/plugins/default_url_options.rb +3 -30
  138. data/lib/shrine/plugins/delete_raw.rb +10 -16
  139. data/lib/shrine/plugins/derivation_endpoint.rb +130 -171
  140. data/lib/shrine/plugins/derivatives.rb +645 -0
  141. data/lib/shrine/plugins/determine_mime_type.rb +9 -21
  142. data/lib/shrine/plugins/download_endpoint.rb +118 -133
  143. data/lib/shrine/plugins/dynamic_storage.rb +5 -11
  144. data/lib/shrine/plugins/entity.rb +158 -0
  145. data/lib/shrine/plugins/form_assign.rb +108 -0
  146. data/lib/shrine/plugins/included.rb +6 -6
  147. data/lib/shrine/plugins/infer_extension.rb +17 -20
  148. data/lib/shrine/plugins/instrumentation.rb +59 -43
  149. data/lib/shrine/plugins/keep_files.rb +3 -15
  150. data/lib/shrine/plugins/metadata_attributes.rb +28 -19
  151. data/lib/shrine/plugins/mirroring.rb +142 -0
  152. data/lib/shrine/plugins/model.rb +160 -0
  153. data/lib/shrine/plugins/module_include.rb +3 -3
  154. data/lib/shrine/plugins/multi_cache.rb +27 -0
  155. data/lib/shrine/plugins/presign_endpoint.rb +27 -28
  156. data/lib/shrine/plugins/pretty_location.rb +15 -9
  157. data/lib/shrine/plugins/processing.rb +22 -9
  158. data/lib/shrine/plugins/rack_file.rb +2 -42
  159. data/lib/shrine/plugins/rack_response.rb +21 -10
  160. data/lib/shrine/plugins/recache.rb +6 -5
  161. data/lib/shrine/plugins/refresh_metadata.rb +13 -11
  162. data/lib/shrine/plugins/remote_url.rb +49 -49
  163. data/lib/shrine/plugins/remove_attachment.rb +12 -6
  164. data/lib/shrine/plugins/remove_invalid.rb +19 -8
  165. data/lib/shrine/plugins/restore_cached_data.rb +13 -7
  166. data/lib/shrine/plugins/sequel.rb +86 -36
  167. data/lib/shrine/plugins/signature.rb +10 -16
  168. data/lib/shrine/plugins/store_dimensions.rb +35 -40
  169. data/lib/shrine/plugins/tempfile.rb +1 -3
  170. data/lib/shrine/plugins/type_predicates.rb +113 -0
  171. data/lib/shrine/plugins/upload_endpoint.rb +28 -24
  172. data/lib/shrine/plugins/upload_options.rb +14 -15
  173. data/lib/shrine/plugins/url_options.rb +31 -0
  174. data/lib/shrine/plugins/validation.rb +80 -0
  175. data/lib/shrine/plugins/validation_helpers.rb +35 -58
  176. data/lib/shrine/plugins/versions.rb +107 -87
  177. data/lib/shrine/plugins.rb +22 -0
  178. data/lib/shrine/storage/file_system.rb +46 -64
  179. data/lib/shrine/storage/linter.rb +42 -7
  180. data/lib/shrine/storage/memory.rb +49 -0
  181. data/lib/shrine/storage/s3.rb +173 -160
  182. data/lib/shrine/uploaded_file.rb +32 -32
  183. data/lib/shrine/version.rb +3 -3
  184. data/lib/shrine.rb +87 -150
  185. data/shrine.gemspec +11 -12
  186. metadata +92 -82
  187. data/doc/migrating_storage.md +0 -76
  188. data/doc/plugins/backup.md +0 -31
  189. data/doc/plugins/copy.md +0 -24
  190. data/doc/plugins/delete_promoted.md +0 -12
  191. data/doc/plugins/direct_upload.md +0 -172
  192. data/doc/plugins/hooks.md +0 -58
  193. data/doc/plugins/logging.md +0 -42
  194. data/doc/plugins/migration_helpers.md +0 -60
  195. data/doc/plugins/moving.md +0 -19
  196. data/doc/plugins/multi_delete.md +0 -20
  197. data/doc/plugins/parallelize.md +0 -16
  198. data/doc/plugins/parsed_json.md +0 -23
  199. data/doc/regenerating_versions.md +0 -143
  200. data/lib/shrine/plugins/background_helpers.rb +0 -5
  201. data/lib/shrine/plugins/backup.rb +0 -90
  202. data/lib/shrine/plugins/copy.rb +0 -50
  203. data/lib/shrine/plugins/delete_promoted.rb +0 -20
  204. data/lib/shrine/plugins/direct_upload.rb +0 -217
  205. data/lib/shrine/plugins/hooks.rb +0 -90
  206. data/lib/shrine/plugins/logging.rb +0 -142
  207. data/lib/shrine/plugins/migration_helpers.rb +0 -70
  208. data/lib/shrine/plugins/moving.rb +0 -57
  209. data/lib/shrine/plugins/multi_delete.rb +0 -32
  210. data/lib/shrine/plugins/parallelize.rb +0 -78
  211. data/lib/shrine/plugins/parsed_json.rb +0 -29
@@ -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,23 +9,24 @@ This plugin is useful for example when using [HTML5 Canvas].
7
9
  plugin :data_uri
8
10
  ```
9
11
 
10
- If your attachment is called "avatar", this plugin will add `#avatar_data_uri`
11
- and `#avatar_data_uri=` methods to your model.
12
+ ## Usage
12
13
 
13
- ```rb
14
- user.avatar #=> nil
15
- user.avatar_data_uri = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUA"
16
- user.avatar #=> #<Shrine::UploadedFile>
14
+ The plugin will add the `#<name>_data_uri` writer to your model, which parses
15
+ the given data URI string and uploads it to temporary storage:
17
16
 
18
- user.avatar.mime_type #=> "image/png"
19
- user.avatar.size #=> 43423
17
+ ```rb
18
+ photo.image_data_uri = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUA"
19
+ photo.image.mime_type #=> "image/png"
20
+ photo.image.size #=> 43423
20
21
  ```
21
22
 
22
- You can also use `#data_uri=` and `#data_uri` methods directly on the
23
- `Shrine::Attacher` (which the model methods just delegate to):
23
+ If you're using `Shrine::Attacher` directly, you can use
24
+ `Attacher#assign_data_uri`:
24
25
 
25
26
  ```rb
26
- attacher.data_uri = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUA"
27
+ attacher.assign_data_uri("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUA")
28
+ attacher.file.mime_type #=> "image/png"
29
+ attacher.file.size #=> 43423
27
30
  ```
28
31
 
29
32
  ## Errors
@@ -36,13 +39,13 @@ plugin :data_uri, error_message: "data URI was invalid"
36
39
  plugin :data_uri, error_message: ->(uri) { I18n.t("errors.data_uri_invalid") }
37
40
  ```
38
41
 
39
- ## Upload options
42
+ ## Uploader options
40
43
 
41
- If you want to pass additional options for `Shrine#upload`, you can use
42
- `#assign_data_uri`:
44
+ Any options passed to `Attacher#assign_data_uri` will be forwarded to
45
+ `Attacher#assign` (and `Shrine#upload`):
43
46
 
44
47
  ```rb
45
- attacher.assign_data_uri(uri, metadata: { "mime_type" => "text/plain" })
48
+ attacher.assign_data_uri(uri, metadata: { "filename" => "nature.jpg" })
46
49
  ```
47
50
 
48
51
  ## File extension
@@ -56,16 +59,14 @@ load the `infer_extension` plugin to infer it from the MIME type.
56
59
  plugin :infer_extension
57
60
  ```
58
61
 
59
- ## API
60
-
61
- ### `Shrine.data_uri`
62
+ ## Parsing data URI
62
63
 
63
64
  If you just want to parse the data URI and create an IO object from it, you can
64
65
  do that with `Shrine.data_uri`. If the data URI cannot be parsed, a
65
66
  `Shrine::Plugins::DataUri::ParseError` will be raised.
66
67
 
67
68
  ```rb
68
- # or YourUploader.data_uri("...")
69
+ # or YourUploader.data_uri(...)
69
70
  io = Shrine.data_uri("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUA")
70
71
  io.content_type #=> "image/png"
71
72
  io.size #=> 21
@@ -90,7 +91,7 @@ io = Shrine.data_uri("data:,content", filename: "foo.txt")
90
91
  io.original_filename #=> "foo.txt"
91
92
  ```
92
93
 
93
- ### `UploadedFile#data_uri` and `UploadedFile#base64`
94
+ ## Generating data URI
94
95
 
95
96
  This plugin also adds `UploadedFile#data_uri` method, which returns a
96
97
  base64-encoded data URI of the file content, and `UploadedFile#base64`, which
@@ -143,6 +144,6 @@ Or disable logging altogether:
143
144
  plugin :data_uri, log_subscriber: nil
144
145
  ```
145
146
 
146
- [data_uri]: /lib/shrine/plugins/data_uri.rb
147
+ [data_uri]: https://github.com/shrinerb/shrine/blob/master/lib/shrine/plugins/data_uri.rb
147
148
  [data URIs]: https://tools.ietf.org/html/rfc2397
148
149
  [HTML5 Canvas]: https://developer.mozilla.org/en-US/docs/Web/API/Canvas_API
@@ -1,19 +1,45 @@
1
- # Default Storage
1
+ ---
2
+ title: Default Storage
3
+ ---
2
4
 
3
- The [`default_storage`][default_storage] plugin enables you to change which
4
- storages are going to be used for this uploader's attacher (the default is
5
- `:cache` and `:store`).
5
+ The [`default_storage`][default_storage] plugin allows you to change the
6
+ default temporary and permanent storage a `Shrine::Attacher` object will use
7
+ (the default is `:cache` and `:store`).
6
8
 
7
9
  ```rb
8
- plugin :default_storage, cache: :special_cache, store: :special_store
10
+ plugin :default_storage, cache: :other_cache, store: :other_store
9
11
  ```
10
12
 
11
- You can also pass a block and choose the values depending on the record values
12
- and the name of the attachment. This is useful if you're using the
13
- `dynamic_storage` plugin. Example:
13
+ If you want the storage to be dynamic based on `Attacher` data, you can use a
14
+ block, and it will be evaluated in context of the `Attacher` instance:
14
15
 
15
16
  ```rb
16
- plugin :default_storage, store: ->(record, name) { :"store_#{record.username}" }
17
+ plugin :default_storage, store: -> {
18
+ if record.is_a?(Photo)
19
+ :photo_store
20
+ else
21
+ :store
22
+ end
23
+ }
17
24
  ```
18
25
 
19
- [default_storage]: /lib/shrine/plugins/default_storage.rb
26
+ You can also set default storage with `Attacher#default_cache` and
27
+ `Attacher#default_store`:
28
+
29
+ ```rb
30
+ # default temporary storage
31
+ Attacher.default_cache :other_cache
32
+ # or
33
+ Attacher.default_cache { :other_cache }
34
+
35
+ # default permanent storage
36
+ Attacher.default_store :other_store
37
+ # or
38
+ Attacher.default_store { :other_store }
39
+ ```
40
+
41
+ The dynamic block is useful in combination with the
42
+ [`dynamic_storage`][dynamic_storage] plugin.
43
+
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,34 +1,51 @@
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
- returned when the attachment is missing.
6
+ returned when there is no attached file.
5
7
 
6
8
  ```rb
7
9
  plugin :default_url
8
10
 
9
- Attacher.default_url do |options|
11
+ Attacher.default_url do |**options|
10
12
  "/#{name}/missing.jpg"
11
13
  end
12
14
  ```
13
15
 
14
- `Attacher#url` returns the default URL when attachment is missing. Any passed
15
- in URL options will be present in the `options` hash.
16
+ The `Attacher#url` method will return the default URL when attachment is
17
+ missing:
16
18
 
17
19
  ```rb
18
- attacher.url #=> "/avatar/missing.jpg"
19
- # or
20
20
  user.avatar_url #=> "/avatar/missing.jpg"
21
+ # or
22
+ attacher.url #=> "/avatar/missing.jpg"
23
+ ```
24
+
25
+ Any URL options passed will be available in the default URL block:
26
+
27
+ ```rb
28
+ attacher.url(foo: "bar")
29
+ ```
30
+ ```rb
31
+ Attacher.default_url do |**options|
32
+ options #=> { foo: "bar" }
33
+ end
21
34
  ```
22
35
 
23
36
  The default URL block is evaluated in the context of an instance of
24
37
  `Shrine::Attacher`.
25
38
 
26
39
  ```rb
27
- Attacher.default_url do |options|
28
- self #=> #<Shrine::Attacher>
40
+ Attacher.default_url do |**options|
41
+ self #=> #<Shrine::Attacher>
42
+
43
+ file #=> #<Shrine::UploadedFile>
44
+ name #=> :avatar
45
+ record #=> #<User>
46
+ context #=> { ... }
29
47
 
30
- name #=> :avatar
31
- record #=> #<User>
48
+ # ...
32
49
  end
33
50
  ```
34
51
 
@@ -41,7 +58,7 @@ option:
41
58
  plugin :default_url, host: "https://example.com"
42
59
  ```
43
60
  ```rb
44
- user.avatar_url #=> "https://example.com/avatar/missing.jpg"
61
+ attacher.url #=> "https://example.com/avatar/missing.jpg"
45
62
  ```
46
63
 
47
- [default_url]: /lib/shrine/plugins/default_url.rb
64
+ [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