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,4 +1,6 @@
1
- # Shrine for CarrierWave Users
1
+ ---
2
+ title: Shrine for CarrierWave Users
3
+ ---
2
4
 
3
5
  This guide is aimed at helping CarrierWave users transition to Shrine, and it
4
6
  consists of three parts:
@@ -7,10 +9,44 @@ consists of three parts:
7
9
  2. Instructions how to migrate and existing app that uses CarrierWave to Shrine
8
10
  3. Extensive reference of CarrierWave's interface with Shrine equivalents
9
11
 
10
- ## Storage
12
+ ## Overview
11
13
 
12
- While in CarrierWave you configure storage in global configuration, in Shrine
13
- storage is a class which you can pass options to during initialization:
14
+ ### Uploader
15
+
16
+ Shrine shares CarrierWave's concept of **uploaders**, classes which encapsulate
17
+ file attachment logic for different file types:
18
+
19
+ ```rb
20
+ class ImageUploader < Shrine
21
+ # attachment logic
22
+ end
23
+ ```
24
+
25
+ However, while CarrierWave uploaders are responsible for most of the
26
+ attachment logic (uploading to temporary/permanent storage, retrieving the
27
+ uploaded file, file validation, processing versions), Shrine distributes
28
+ these responsibilities across several core classes:
29
+
30
+ | Class | Description |
31
+ | :---- | :----------- |
32
+ | `Shrine` | handles uploads, metadata extraction, location generation |
33
+ | `Shrine::UploadedFile` | exposes metadata, implements downloading, URL generation, deletion |
34
+ | `Shrine::Attacher` | handles caching & storing, dirty tracking, persistence, versions |
35
+
36
+ Shrine uploaders themselves are functional: they receive a file on the input
37
+ and return the uploaded file on the output. There are no state changes.
38
+
39
+ ```rb
40
+ uploader = ImageUploader.new(:store)
41
+ uploaded_file = uploader.upload(file, :store)
42
+ uploaded_file #=> #<Shrine::UploadedFile>
43
+ uploaded_file.url #=> "https://my-bucket.s3.amazonaws.com/store/kfds0lg9rer.jpg"
44
+ uploaded_file.download #=> #<File:/tmp/path/to/file>
45
+ ```
46
+
47
+ ### Storage
48
+
49
+ In CarrierWave, you configure storage in global configuration:
14
50
 
15
51
  ```rb
16
52
  CarrierWave.configure do |config|
@@ -24,6 +60,9 @@ CarrierWave.configure do |config|
24
60
  config.fog_directory = "my-bucket"
25
61
  end
26
62
  ```
63
+
64
+ In Shrine, the configuration options are passed directly to the storage class:
65
+
27
66
  ```rb
28
67
  Shrine.storages[:store] = Shrine::Storage::S3.new(
29
68
  bucket: "my-bucket",
@@ -33,11 +72,11 @@ Shrine.storages[:store] = Shrine::Storage::S3.new(
33
72
  )
34
73
  ```
35
74
 
36
- In CarrierWave temporary storage cannot be configured; it saves and retrieves
37
- files from the filesystem, you can only set the directory. With Shrine both
38
- temporary (`:cache`) and permanent (`:store`) storage are first-class citizens
39
- and fully configurable, so you can also have files *cached* on S3 (preferrably
40
- via [direct uploads]):
75
+ #### Temporary storage
76
+
77
+ Where CarrierWave's temporary storage is hardcoded to disk, Shrine can use any
78
+ storage for temporary storage. So, if you have multiple servers or want to do
79
+ [direct uploads], you can use AWS S3 as temporary storage:
41
80
 
42
81
  ```rb
43
82
  Shrine.storages = {
@@ -46,32 +85,52 @@ Shrine.storages = {
46
85
  }
47
86
  ```
48
87
 
49
- ## Uploader
88
+ ### Persistence
50
89
 
51
- Shrine shares CarrierWave's concept of *uploaders*, classes which encapsulate
52
- file attachment logic for different file types:
90
+ While CarrierWave persists only the filename of the original uploaded file,
91
+ Shrine persists storage and metadata information as well:
53
92
 
54
93
  ```rb
55
- class ImageUploader < Shrine
56
- # attachment logic
57
- end
94
+ {
95
+ "id": "path/to/image.jpg",
96
+ "storage": "store",
97
+ "metadata": {
98
+ "filename": "nature.jpg",
99
+ "size": 4739472,
100
+ "mime_type": "image/jpeg"
101
+ }
102
+ }
58
103
  ```
59
104
 
60
- However, uploaders in CarrierWave are very broad; in addition to uploading and
61
- deleting files, they also represent the uploaded file. Shrine has a separate
62
- `Shrine::UploadedFile` class which represents the uploaded file.
105
+ This way we have all information about uploaded files, without having to
106
+ retrieve the file from the storage.
63
107
 
64
108
  ```rb
65
- uploaded_file = ImageUploader.upload(file, :store)
66
- uploaded_file #=> #<Shrine::UploadedFile>
67
- uploaded_file.url #=> "https://my-bucket.s3.amazonaws.com/store/kfds0lg9rer.jpg"
68
- uploaded_file.download #=> #<File:/tmp/path/to/file>
109
+ photo.image.id #=> "path/to/image.jpg"
110
+ photo.image.storage_key #=> :store
111
+ photo.image.metadata #=> { "filename" => "...", "size" => ..., "mime_type" => "..." }
112
+
113
+ photo.image.original_filename #=> "nature.jpg"
114
+ photo.image.size #=> 4739472
115
+ photo.image.mime_type #=> "image/jpeg"
69
116
  ```
70
117
 
71
- ## Processing
118
+ #### Location
119
+
120
+ CarrierWave persists only the filename of the uploaded file, and recalculates
121
+ the full location dynamically based on location configuration. This can be
122
+ dangerous, because if some component of the location happens to change, all
123
+ existing links might become invalid.
72
124
 
73
- In contrast to CarrierWave's class-level DSL, in Shrine processing is defined
74
- and performed on the instance-level.
125
+ To avoid this, Shrine persists the full location on attachment, and uses it
126
+ when generating file URL. So, even if you change how file locations are
127
+ generated, existing files that are on old locations will still remain
128
+ accessible.
129
+
130
+ ### Processing
131
+
132
+ CarrierWave uses a class-level DSL for generating versions, which internally
133
+ uses uploader subclassing and does in-place processing.
75
134
 
76
135
  ```rb
77
136
  class ImageUploader < CarrierWave::Uploader::Base
@@ -91,6 +150,9 @@ class ImageUploader < CarrierWave::Uploader::Base
91
150
  end
92
151
  ```
93
152
 
153
+ In contrast, in Shrine you perform processing on the instance level as a
154
+ functional transformation, which is a lot simpler and more flexible:
155
+
94
156
  ```rb
95
157
  require "image_processing/mini_magick"
96
158
 
@@ -109,23 +171,45 @@ class ImageUploader < Shrine
109
171
  end
110
172
  ```
111
173
 
112
- CarrierWave performs processing before validations, which is a huge security
113
- issue, as it allows users to give arbitrary files to your processing tool, even
114
- if you have validations. With Shrine you can perform processing after
115
- validations.
174
+ #### Retrieving versions
116
175
 
117
- Shrine doesn't have a built-in way of regenerating versions, but there is an
118
- extensive [Managing Derivatives] guide.
176
+ When retrieving versions, CarrierWave returns a list of declared versions which
177
+ may or may not have been generated. In contrast, Shrine persists data of
178
+ uploaded processed files into the database (including any extracted metadata),
179
+ which then becomes the source of truth on which versions have been generated.
119
180
 
120
- ### Validations
181
+ ```rb
182
+ photo.image #=> #<Shrine::UploadedFile @id="original.jpg" ...>
183
+ photo.image_derivatives #=> {}
121
184
 
122
- Like with processing, validations in Shrine are also defined and performed on
123
- instance-level:
185
+ photo.image_derivatives! # triggers processing
186
+ photo.image_derivatives #=>
187
+ # {
188
+ # large: #<Shrine::UploadedFile @id="large.jpg" @metadata={"size"=>873232, ...} ...>,
189
+ # medium: #<Shrine::UploadedFile @id="medium.jpg" @metadata={"size"=>94823, ...} ...>,
190
+ # small: #<Shrine::UploadedFile @id="small.jpg" @metadata={"size"=>37322, ...} ...>,
191
+ # }
192
+ ```
193
+
194
+ #### Reprocessing versions
195
+
196
+ Shrine doesn't have a built-in way of regenerating versions, because that has
197
+ to be written and optimized differently depending on what versions have changed
198
+ which persistence library you're using, how many records there are in the table
199
+ etc.
200
+
201
+ However, there is an extensive guide for [Managing Derivatives], which provides
202
+ instructions on how to make these changes safely and with zero downtime.
203
+
204
+ ### Validation
205
+
206
+ File validation in Shrine is also instance-level, which allows using
207
+ conditionals:
124
208
 
125
209
  ```rb
126
210
  class ImageUploader < CarrierWave::Uploader::Base
127
211
  def extension_whitelist
128
- %w[jpg jpeg gif png]
212
+ %w[jpg jpeg png webp]
129
213
  end
130
214
 
131
215
  def content_type_whitelist
@@ -143,91 +227,43 @@ class ImageUploader < Shrine
143
227
  plugin :validation_helpers
144
228
 
145
229
  Attacher.validate do
146
- validate_extension %w[jpg jpeg gif png]
147
- validate_mime_type %w[image/jpeg image/gif image/png]
148
230
  validate_max_size 10*1024*1024
231
+ validate_extension %w[jpg jpeg png webp]
232
+
233
+ if validate_mime_type %w[image/jpeg image/png image/webp]
234
+ validate_max_dimensions [5000, 5000]
235
+ end
149
236
  end
150
237
  end
151
238
  ```
152
239
 
153
- ## Attachments
240
+ #### Custom metadata
154
241
 
155
- Like CarrierWave, Shrine also provides integrations with ORMs. It ships with
156
- plugins for both Sequel and ActiveRecord, but can also be used with just PORO
157
- models.
242
+ With Shrine you can also extract and validate any custom metadata:
158
243
 
159
244
  ```rb
160
- Shrine.plugin :sequel # if you're using Sequel
161
- Shrine.plugin :activerecord # if you're using ActiveRecord
162
- ```
245
+ class VideoUploader < Shrine
246
+ plugin :add_metadata
247
+ plugin :validation
163
248
 
164
- Instead of giving you class methods for "mounting" uploaders, in Shrine you
165
- generate attachment modules which you simply include in your models, which
166
- gives your models similar set of methods that CarrierWave gives:
249
+ add_metadata :duration do |io|
250
+ FFMPEG::Movie.new(io.path).duration
251
+ end
167
252
 
168
- ```rb
169
- class Photo < ActiveRecord::Base
170
- extend CarrierWave::ActiveRecord # done automatically by CarrierWave
171
- mount_uploader :image, ImageUploader
172
- end
173
- ```
174
- ```rb
175
- class Photo < ActiveRecord::Base
176
- include ImageUploader::Attachment(:image)
253
+ Attacher.validate do
254
+ if file.duration > 5*60*60
255
+ errors << "must not be longer than 5 hours"
256
+ end
257
+ end
177
258
  end
178
259
  ```
179
260
 
180
- ### Attachment column
181
-
182
- You models are required to have the `<attachment>_data` column, which Shrine
183
- uses to save storage, location, and metadata of the uploaded file.
184
-
185
- ```rb
186
- photo.image_data #=>
187
- # {
188
- # "storage": "store",
189
- # "id": "photo/1/image/0d9o8dk42.png",
190
- # "metadata": {
191
- # "filename": "nature.png",
192
- # "size": 49349138,
193
- # "mime_type": "image/png"
194
- # }
195
- # }
196
-
197
- photo.image.original_filename #=> "nature.png"
198
- photo.image.size #=> 49349138
199
- photo.image.mime_type #=> "image/png"
200
- ```
201
-
202
- This is much more powerful than storing only the filename like CarrierWave
203
- does, as it allows you to also store any additional metadata that you might
204
- want to extract.
205
-
206
- Unlike CarrierWave, Shrine will store this information for each processed
207
- version, making them first-class citizens:
208
-
209
- ```rb
210
- photo.image #=> #<Shrine::UploadedFile>
211
- photo.image.width #=> 800
212
-
213
- photo.image(:thumb) #=> #<Shrine::UploadedFile>
214
- photo.image(:thumb).width #=> 300
215
- ```
216
-
217
- Also, since CarrierWave stores only the filename, it has to recalculate the
218
- full location each time it wants to generate the URL. That makes it really
219
- difficult to move files to a new location, because changing how the location is
220
- generated will now cause incorrect URLs to be generated for all existing files.
221
- Shrine calculates the whole location only once and saves it to the column.
222
-
223
261
  ### Multiple uploads
224
262
 
225
- Shrine doesn't have support for multiple uploads like CarrierWave does, instead
226
- it expects that you will attach each file to a separate database record. This
227
- is a good thing, because the implementation is specific to the ORM you're
228
- using, and it's analogous to how you would implement any nested one-to-many
229
- associations. Take a look at the [demo app] which shows how easy it is to
230
- implement multiple uploads.
263
+ Shrine doesn't have support for multiple uploads out-of-the-box like
264
+ CarrierWave does. Instead, you can implement them using a separate table with a
265
+ one-to-many relationship to which the files will be attached. The [Multiple
266
+ Files] guide explains this setup in more detail.
231
267
 
232
268
  ## Migrating from CarrierWave
233
269
 
@@ -653,9 +689,10 @@ multipart or not.
653
689
 
654
690
  ### `CarrierWave::Storage::Fog`
655
691
 
656
- You can use [`Shrine::Storage::S3`] \(built-in\),
657
- [`Shrine::Storage::GoogleCloudStorage`], or generic [`Shrine::Storage::Fog`]
658
- storage. The reference will assume you're using S3 storage.
692
+ You can use [`Shrine::Storage::S3`][S3] (built-in),
693
+ [`Shrine::Storage::GoogleCloudStorage`][shrine-gcs], or generic
694
+ [`Shrine::Storage::Fog`][shrine-fog] storage. The reference will assume you're
695
+ using S3 storage.
659
696
 
660
697
  #### `:fog_credentials`, `:fog_directory`
661
698
 
@@ -704,11 +741,9 @@ Shrine allows you to override the S3 endpoint:
704
741
  Shrine::Storage::S3.new(use_accelerate_endpoint: true, **options)
705
742
  ```
706
743
 
707
- [image_processing]: https://github.com/janko/image_processing
708
- [demo app]: https://github.com/shrinerb/shrine/tree/master/demo
709
- [Managing Derivatives]: /doc/changing_derivatives.md#readme
744
+ [Managing Derivatives]: https://shrinerb.com/docs/changing-derivatives
745
+ [direct uploads]: https://shrinerb.com/docs/getting-started#direct-uploads
746
+ [S3]: https://shrinerb.com/docs/storage/s3
747
+ [shrine-gcs]: https://github.com/renchap/shrine-google_cloud_storage
710
748
  [shrine-fog]: https://github.com/shrinerb/shrine-fog
711
- [direct uploads]: /doc/direct_s3.md#readme
712
- [`Shrine::Storage::S3`]: /doc/storage/s3.md#readme
713
- [`Shrine::Storage::GoogleCloudStorage`]: https://github.com/renchap/shrine-google_cloud_storage
714
- [`Shrine::Storage::Fog`]: https://github.com/shrinerb/shrine-fog
749
+ [Multiple Files]: https://shrinerb.com/docs/multiple-files
@@ -1,4 +1,7 @@
1
- # Managing Derivatives
1
+ ---
2
+ id: changing-derivatives
3
+ title: Managing Derivatives
4
+ ---
2
5
 
3
6
  This guide shows how to add, create, update, and remove [derivatives] for an
4
7
  app in production already handling file attachments, with zero downtime.
@@ -22,15 +25,6 @@ class Photo < ActiveRecord::Base
22
25
  end
23
26
  ```
24
27
 
25
- ## Contents
26
-
27
- * [Adding derivatives](#adding-derivatives)
28
- * [Reprocessing all derivatives](#reprocessing-all-derivatives)
29
- * [Reprocessing certain derivatives](#reprocessing-certain-derivatives)
30
- * [Adding new derivatives](#adding-new-derivatives)
31
- * [Removing derivatives](#removing-derivatives)
32
- * [Backgrounding](#backgrounding)
33
-
34
28
  ## Adding derivatives
35
29
 
36
30
  *Scenario: Your app is currently working only with original files, and you want
@@ -311,4 +305,4 @@ class MakeChangeJob
311
305
  end
312
306
  ```
313
307
 
314
- [derivatives]: /doc/plugins/derivatives.md#readme
308
+ [derivatives]: https://shrinerb.com/docs/plugins/derivatives
@@ -1,4 +1,7 @@
1
- # Migrating File Locations
1
+ ---
2
+ id: changing-location
3
+ title: Migrating File Locations
4
+ ---
2
5
 
3
6
  This guide shows how to migrate the location of uploaded files on the same
4
7
  storage in production, with zero downtime.
@@ -56,10 +59,10 @@ Photo.find_each do |photo|
56
59
 
57
60
  begin
58
61
  attacher.atomic_persist # persist changes if attachment has not changed in the meantime
59
- old_attacher.destroy # delete files on old location
62
+ old_attacher.destroy_attached # delete files on old location
60
63
  rescue Shrine::AttachmentChanged, # attachment has changed during reuploading
61
64
  ActiveRecord::RecordNotFound # record has been deleted during reuploading
62
- attacher.destroy # delete now orphaned files
65
+ attacher.destroy_attached # delete now orphaned files
63
66
  end
64
67
  end
65
68
  ```
@@ -100,9 +103,9 @@ class MoveFilesJob
100
103
  attacher.set_derivatives attacher.upload_derivatives(attacher.derivatives)
101
104
 
102
105
  attacher.atomic_persist
103
- old_attacher.destroy
106
+ old_attacher.destroy_attached
104
107
  rescue Shrine::AttachmentChanged, ActiveRecord::RecordNotFound
105
- attacher&.destroy
108
+ attacher&.destroy_attached
106
109
  end
107
110
  end
108
111
  ```
@@ -1,4 +1,7 @@
1
- # Migrating File Storage
1
+ ---
2
+ id: changing-storage
3
+ title: Migrating File Storage
4
+ ---
2
5
 
3
6
  This guides shows how to move file attachments to a different storage in
4
7
  production, with zero downtime.
@@ -104,4 +107,4 @@ Shrine.storages = {
104
107
  - Shrine.plugin :mirroring, mirror: { store: :s3 } # mirror to :s3 storage
105
108
  ```
106
109
 
107
- [mirroring backgrounding]: /doc/plugins/mirroring.md#backgrounding
110
+ [mirroring backgrounding]: https://shrinerb.com/docs/plugins/mirroring#backgrounding
@@ -1,4 +1,7 @@
1
- # Writing an Persistence Plugin
1
+ ---
2
+ id: creating-persistence-plugins
3
+ title: Writing a Persistence Plugin
4
+ ---
2
5
 
3
6
  This guide explains some conventions for writing Shrine plugins that integrate
4
7
  with persistence libraries such as Active Record, Sequel, ROM and Mongoid. It
@@ -118,12 +121,12 @@ module Shrine::Plugins::Raptor
118
121
  end
119
122
  ```
120
123
 
121
- [Writing a Plugin]: /doc/creating_plugins.md#readme
124
+ [Writing a Plugin]: https://shrinerb.com/docs/creating-plugins
122
125
  [Active Record pattern]: https://www.martinfowler.com/eaaCatalog/activeRecord.html
123
- [model]: /doc/plugins/model.md#readme
124
- [entity]: /doc/plugins/entity.md#readme
126
+ [model]: https://shrinerb.com/docs/plugins/model
127
+ [entity]: https://shrinerb.com/docs/plugins/entity
125
128
  [Repository pattern]: https://martinfowler.com/eaaCatalog/repository.html
126
- [backgrounding]: /doc/plugins/backgrounding.md#readme
127
- [atomic_helpers]: /doc/plugins/atomic_helpers.md#readme
129
+ [backgrounding]: https://shrinerb.com/docs/plugins/backgrounding
130
+ [atomic_helpers]: https://shrinerb.com/docs/plugins/atomic_helpers
128
131
  [activerecord]: /lib/shrine/plugins/activerecord.rb
129
132
  [sequel]: /lib/shrine/plugins/sequel.rb