shrine 3.0.0 → 3.2.2

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 (93) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +87 -33
  3. data/LICENSE.txt +1 -1
  4. data/README.md +94 -4
  5. data/doc/advantages.md +35 -18
  6. data/doc/attacher.md +16 -17
  7. data/doc/carrierwave.md +75 -34
  8. data/doc/changing_derivatives.md +39 -39
  9. data/doc/design.md +134 -85
  10. data/doc/external/articles.md +56 -41
  11. data/doc/external/extensions.md +38 -34
  12. data/doc/getting_started.md +182 -112
  13. data/doc/metadata.md +79 -43
  14. data/doc/multiple_files.md +5 -3
  15. data/doc/paperclip.md +110 -42
  16. data/doc/plugins/activerecord.md +5 -5
  17. data/doc/plugins/add_metadata.md +92 -35
  18. data/doc/plugins/backgrounding.md +12 -2
  19. data/doc/plugins/column.md +36 -7
  20. data/doc/plugins/data_uri.md +2 -2
  21. data/doc/plugins/default_url.md +6 -3
  22. data/doc/plugins/derivation_endpoint.md +26 -28
  23. data/doc/plugins/derivatives.md +205 -169
  24. data/doc/plugins/determine_mime_type.md +2 -2
  25. data/doc/plugins/entity.md +3 -3
  26. data/doc/plugins/form_assign.md +5 -5
  27. data/doc/plugins/included.md +25 -5
  28. data/doc/plugins/infer_extension.md +2 -2
  29. data/doc/plugins/instrumentation.md +1 -1
  30. data/doc/plugins/metadata_attributes.md +21 -10
  31. data/doc/plugins/model.md +4 -4
  32. data/doc/plugins/persistence.md +1 -0
  33. data/doc/plugins/refresh_metadata.md +5 -4
  34. data/doc/plugins/remote_url.md +8 -3
  35. data/doc/plugins/remove_invalid.md +9 -1
  36. data/doc/plugins/sequel.md +4 -4
  37. data/doc/plugins/signature.md +11 -2
  38. data/doc/plugins/store_dimensions.md +2 -2
  39. data/doc/plugins/type_predicates.md +96 -0
  40. data/doc/plugins/upload_endpoint.md +7 -11
  41. data/doc/plugins/upload_options.md +1 -1
  42. data/doc/plugins/url_options.md +2 -2
  43. data/doc/plugins/validation.md +14 -4
  44. data/doc/plugins/validation_helpers.md +3 -3
  45. data/doc/plugins/versions.md +11 -11
  46. data/doc/processing.md +289 -125
  47. data/doc/refile.md +39 -18
  48. data/doc/release_notes/2.19.0.md +1 -1
  49. data/doc/release_notes/3.0.0.md +275 -258
  50. data/doc/release_notes/3.0.1.md +22 -0
  51. data/doc/release_notes/3.1.0.md +73 -0
  52. data/doc/release_notes/3.2.0.md +96 -0
  53. data/doc/release_notes/3.2.1.md +32 -0
  54. data/doc/release_notes/3.2.2.md +14 -0
  55. data/doc/securing_uploads.md +3 -3
  56. data/doc/storage/file_system.md +1 -1
  57. data/doc/storage/memory.md +19 -0
  58. data/doc/storage/s3.md +105 -86
  59. data/doc/testing.md +2 -2
  60. data/doc/upgrading_to_3.md +115 -33
  61. data/doc/validation.md +3 -2
  62. data/lib/shrine.rb +8 -8
  63. data/lib/shrine/attacher.rb +19 -14
  64. data/lib/shrine/attachment.rb +5 -5
  65. data/lib/shrine/plugins.rb +22 -0
  66. data/lib/shrine/plugins/add_metadata.rb +12 -3
  67. data/lib/shrine/plugins/default_storage.rb +6 -6
  68. data/lib/shrine/plugins/default_url.rb +1 -1
  69. data/lib/shrine/plugins/derivation_endpoint.rb +10 -6
  70. data/lib/shrine/plugins/derivatives.rb +19 -17
  71. data/lib/shrine/plugins/determine_mime_type.rb +3 -3
  72. data/lib/shrine/plugins/entity.rb +6 -6
  73. data/lib/shrine/plugins/metadata_attributes.rb +1 -1
  74. data/lib/shrine/plugins/model.rb +3 -3
  75. data/lib/shrine/plugins/presign_endpoint.rb +2 -2
  76. data/lib/shrine/plugins/pretty_location.rb +1 -1
  77. data/lib/shrine/plugins/processing.rb +1 -1
  78. data/lib/shrine/plugins/refresh_metadata.rb +2 -2
  79. data/lib/shrine/plugins/remote_url.rb +3 -3
  80. data/lib/shrine/plugins/remove_invalid.rb +10 -5
  81. data/lib/shrine/plugins/signature.rb +7 -6
  82. data/lib/shrine/plugins/store_dimensions.rb +18 -9
  83. data/lib/shrine/plugins/type_predicates.rb +113 -0
  84. data/lib/shrine/plugins/upload_endpoint.rb +3 -3
  85. data/lib/shrine/plugins/upload_options.rb +2 -2
  86. data/lib/shrine/plugins/url_options.rb +2 -2
  87. data/lib/shrine/plugins/validation.rb +9 -7
  88. data/lib/shrine/storage/linter.rb +4 -4
  89. data/lib/shrine/storage/s3.rb +62 -38
  90. data/lib/shrine/uploaded_file.rb +5 -1
  91. data/lib/shrine/version.rb +2 -2
  92. data/shrine.gemspec +6 -7
  93. metadata +23 -29
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6c4cf7d403c331ddb66dc01ea8e9210a827065c08fd206d89be8aa1dac24775b
4
- data.tar.gz: 9a1b304b4fd4c9640f1bda7904c6402490af9456c896d69bd815fcf8f34ea1e2
3
+ metadata.gz: 26dd77c39f9d5b7cc4240eacea23823453959aad469acc1d86571f129c24c347
4
+ data.tar.gz: 9c25f9de3f8c8be835e096da01b47c0636e03158b423a306b89895de05ca4294
5
5
  SHA512:
6
- metadata.gz: 0eeb00bf6fa625a51f993bda58e0d016b6c85d0831f9be4ce6f914c720054f03684f83617b963f894b51216b96f9ad42eddbcfcf4f717521123d474397c8e3d6
7
- data.tar.gz: dd07bd03ea16adf721fdbd8568aa33f1f47a36a32ac5c82537721492c12a21e1b169ebbf8b2872fcb4c938f68bbbde9a1aff6b447fee0a50663898c105e2c62e
6
+ metadata.gz: 4ae941f20c889d15300bb0a3bb522f8ad9f0cbd9bb80578246bc4d5ed37b1177ecc911172a405872919210bdaa05b1e67f23d77fc97d9c827ef85b01898dd336
7
+ data.tar.gz: 16fbafcc5d29e70f6d0d4a36fc2123a4a8f705345021b00e87c863826d73970a7bd8116aa19ad5c3a2a03763b0e5e435398ae15a21428d0b932c52a7bb648f8e
@@ -1,4 +1,56 @@
1
- ## 3.0.0 (14-10-2019)
1
+ ## 3.2.2 (2020-08-05)
2
+
3
+ * `s3` – Fix `S3#open` not working on aws-sdk-core 3.104 and above (@janko)
4
+
5
+ ## 3.2.1 (2020-01-12)
6
+
7
+ * `derivation_endpoint` – Use `Rack::Files` constant on Rack >= 2.1 (@janko)
8
+
9
+ * Fix Ruby 2.7 warnings regarding separation of positional and keyword arguments (@janko)
10
+
11
+ * `s3` – Make `S3#open` handle empty S3 objects (@janko)
12
+
13
+ ## 3.2.0 (2019-12-17) [[release notes]](https://shrinerb.com/docs/release_notes/3.2.0)
14
+
15
+ * `validation` – Run validation on `Attacher#attach` & `Attacher#attach_cached` instead of `Attacher#change` (@janko)
16
+
17
+ * `remove_invalid` – Activate also when `Attacher#validate` is run manually (@janko)
18
+
19
+ * `remove_invalid` – Fix incompatibility with `derivatives` plugin (@janko)
20
+
21
+ * `type_predicates` – Add new plugin with convenient `UploadedFile` predicate methods based on MIME type (@janko)
22
+
23
+ * `core` – Allow assigning back current attached file data (@janko)
24
+
25
+ * `derivatives` – Fix `:derivative` value inconsistency when derivatives are being promoted (@janko)
26
+
27
+ * `add_metadata` – Add `#add_metadata` method for adding metadata to uploaded files (@janko)
28
+
29
+ * `derivatives` – Add `:io` and `:attacher` values to instrumentation event payload (@janko)
30
+
31
+ ## 3.1.0 (2019-11-15) [[release notes]](https://shrinerb.com/docs/release_notes/3.1.0)
32
+
33
+ * `default_storage` – Coerce storage key to symbol in `Attacher#cache_key` & `Attacher#store_key` (@janko)
34
+
35
+ * `core` – Coerce storage key to symbol in `Attacher#cache_key` & `Attacher#store_key` (@janko)
36
+
37
+ * `add_metadata` – Define metadata methods only for the target uploader class (@janko)
38
+
39
+ * `derivatives` – Add `:storage` option to `Attacher#create_derivatives` (@janko)
40
+
41
+ * `store_dimensions` – Propagate exceptions on loading `ruby-vips` in `:vips` analyzer (@janko)
42
+
43
+ * `signature` – Allow skipping rewinding by passing `rewind: false` to `Shrine.signature` (@janko)
44
+
45
+ * `derivatives` – Add `Attacher.derivatives` alias for `Attacher.derivatives_processor` (@janko)
46
+
47
+ ## 3.0.1 (2019-10-17) [[release notes]](https://shrinerb.com/docs/release_notes/3.0.1)
48
+
49
+ * `metadata_attributes` – Fix exception being raised when there is no attached file (@janko)
50
+
51
+ * `core` – Simplify `UploadedFile#inspect` output (@janko)
52
+
53
+ ## 3.0.0 (2019-10-14) [[release notes]](https://shrinerb.com/docs/release_notes/3.0.0)
2
54
 
3
55
  * `derivation_endpoint` – Pass `action: :derivation` when uploading derivation results (@janko)
4
56
 
@@ -230,6 +282,8 @@
230
282
 
231
283
  * `core` – Add `Attacher#data` and `Attacher.from_data` for dumping to and loading from a Hash (@janko)
232
284
 
285
+ * `core` – Change `Attacher#assign` to raise exception when non-cached file is assigned (@janko)
286
+
233
287
  * `core` – Enable `Attacher#assign` to accept cached file data as a Hash (@janko)
234
288
 
235
289
  * `core` – Add `Attacher#file` alias for `Attacher#get` (@janko)
@@ -356,7 +410,7 @@
356
410
 
357
411
  * `s3` – Drop support for `aws-sdk` 2.x (@janko)
358
412
 
359
- ## 2.19.0 (2019-07-18)
413
+ ## 2.19.0 (2019-07-18) [[release notes]](https://shrinerb.com/docs/release_notes/2.19.0)
360
414
 
361
415
  * `pretty_location` – Allow specifying a different identifier from `id` (@00dav00)
362
416
 
@@ -412,7 +466,7 @@
412
466
 
413
467
  * `core` – Allow registering storage objects under string keys (@janko)
414
468
 
415
- ## 2.18.0 (2019-06-24)
469
+ ## 2.18.0 (2019-06-24) [[release notes]](https://shrinerb.com/docs/release_notes/2.18.0)
416
470
 
417
471
  * `core` – Add `Shrine.upload` method as a shorthand for `Shrine.new(...).upload(...)` (@janko)
418
472
 
@@ -436,7 +490,7 @@
436
490
 
437
491
  * `parsed_json` – Fix overriden `Attacher#assign` not accepting second argument (@janko)
438
492
 
439
- ## 2.17.0 (2019-05-06)
493
+ ## 2.17.0 (2019-05-06) [[release notes]](https://shrinerb.com/docs/release_notes/2.17.0)
440
494
 
441
495
  * `data_uri` – Add `Attacher#assign_data_uri` which accepts additional `Shrine#upload` options (@janko)
442
496
 
@@ -486,7 +540,7 @@
486
540
 
487
541
  * `parsed_json` – Accepts hashes with symbols keys (@aglushkov)
488
542
 
489
- ## 2.16.0 (2019-02-18)
543
+ ## 2.16.0 (2019-02-18) [[release notes]](https://shrinerb.com/docs/release_notes/2.16.0)
490
544
 
491
545
  * `derivation_endpoint` – Add `:upload_open_options` for download option for derivation result (@janko)
492
546
 
@@ -512,7 +566,7 @@
512
566
 
513
567
  * Fix `store_dimensions` plugin making second argument in `Shrine#extract_metadata` mandatory (@jrochkind)
514
568
 
515
- ## 2.15.0 (2019-02-08)
569
+ ## 2.15.0 (2019-02-08) [[release notes]](https://shrinerb.com/docs/release_notes/2.15.0)
516
570
 
517
571
  * Add `derivation_endpoint` plugin for processing uploaded files on-the-fly (@janko)
518
572
 
@@ -522,7 +576,7 @@
522
576
 
523
577
  * Yield a new File object on `Shrine.with_file` when `tempfile` plugin is loaded (@janko)
524
578
 
525
- ## 2.14.0 (2018-12-27)
579
+ ## 2.14.0 (2018-12-27) [[release notes]](https://shrinerb.com/docs/release_notes/2.14.0)
526
580
 
527
581
  * Add `tempfile` plugin for easier reusing of the same uploaded file copy on disk (@janko)
528
582
 
@@ -592,7 +646,7 @@
592
646
 
593
647
  * Use a guard raise cause for `bucket` argument in S3 for an appropriate error message (@ardecvz)
594
648
 
595
- ## 2.13.0 (2018-11-04)
649
+ ## 2.13.0 (2018-11-04) [[release notes]](https://shrinerb.com/docs/release_notes/2.13.0)
596
650
 
597
651
  * Specify UTF-8 charset in `Content-Type` response header in `presign_endpoint` plugin (@janko)
598
652
 
@@ -624,7 +678,7 @@
624
678
 
625
679
  * In `S3#upload` deprecate using aws-sdk-s3 lower than 1.14 when uploading IO objects of unknown size (@janko)
626
680
 
627
- ## 2.12.0 (2018-08-22)
681
+ ## 2.12.0 (2018-08-22) [[release notes]](https://shrinerb.com/docs/release_notes/2.12.0)
628
682
 
629
683
  * Ignore nil values when assigning files from a remote URL (@janko)
630
684
 
@@ -652,7 +706,7 @@
652
706
 
653
707
  * Make `UploadedFile#open` always open a new IO object and close the previous one (@janko)
654
708
 
655
- ## 2.11.0 (2018-04-28)
709
+ ## 2.11.0 (2018-04-28) [[release notes]](https://shrinerb.com/docs/release_notes/2.11.0)
656
710
 
657
711
  * Add `Shrine.with_file` for temporarily converting an IO-like object into a file (@janko)
658
712
 
@@ -680,7 +734,7 @@
680
734
 
681
735
  * Deprecate `direct_upload` plugin in favor of `upload_endpoint` and `presign_endpoint` plugins (@janko)
682
736
 
683
- ## 2.10.0 (2018-03-28)
737
+ ## 2.10.0 (2018-03-28) [[release notes]](https://shrinerb.com/docs/release_notes/2.10.0)
684
738
 
685
739
  * Add `:fastimage` analyzer to `determine_mime_type` plugin (@mokolabs)
686
740
 
@@ -702,7 +756,7 @@
702
756
 
703
757
  * Inherit the logger on subclassing `Shrine` and make it shared across subclasses (@hmistry)
704
758
 
705
- ## 2.9.0 (2018-01-27)
759
+ ## 2.9.0 (2018-01-27) [[release notes]](https://shrinerb.com/docs/release_notes/2.9.0)
706
760
 
707
761
  * Support arrays of files in `versions` plugin (@janko)
708
762
 
@@ -726,7 +780,7 @@
726
780
 
727
781
  * Allow passing options to `Model#<attachment>_attacher` for overriding `Attacher` options (@janko)
728
782
 
729
- ## 2.8.0 (2017-10-11)
783
+ ## 2.8.0 (2017-10-11) [[release notes]](https://shrinerb.com/docs/release_notes/2.8.0)
730
784
 
731
785
  * Expand relative directory paths when initializing `Storage::FileSystem` (@janko)
732
786
 
@@ -756,7 +810,7 @@
756
810
 
757
811
  * Update `direct_upload` plugin to support Roda 3 (@janko)
758
812
 
759
- ## 2.7.0 (2017-09-11)
813
+ ## 2.7.0 (2017-09-11) [[release notes]](https://shrinerb.com/docs/release_notes/2.7.0)
760
814
 
761
815
  * Deprecate the `Shrine::DownloadEndpoint` constant over `Shrine.download_endpoint` (@janko)
762
816
 
@@ -824,11 +878,11 @@
824
878
 
825
879
  * Don't add a newline at the end of the base64-formatted signature (@janko)
826
880
 
827
- ## 2.6.1 (2017-04-12)
881
+ ## 2.6.1 (2017-04-12) [[release notes]](https://shrinerb.com/docs/release_notes/2.6.1)
828
882
 
829
883
  * Fix `download_endpoint` returning incorrect reponse body in some cases (@janko)
830
884
 
831
- ## 2.6.0 (2017-04-04)
885
+ ## 2.6.0 (2017-04-04) [[release notes]](https://shrinerb.com/docs/release_notes/2.6.0)
832
886
 
833
887
  * Make `Shrine::Storage::FileSystem#path` public which returns path to the file as a `Pathname` object (@janko)
834
888
 
@@ -900,7 +954,7 @@
900
954
 
901
955
  * Raise `Shrine::Error` when `Shrine#generate_location` returns nil (@janko)
902
956
 
903
- ## 2.5.0 (2016-11-11)
957
+ ## 2.5.0 (2016-11-11) [[release notes]](https://shrinerb.com/docs/release_notes/2.5.0)
904
958
 
905
959
  * Add `Attacher.default_url` as the idiomatic way of declaring default URLs (@janko)
906
960
 
@@ -926,7 +980,7 @@
926
980
 
927
981
  * Make it possible to extract multiple metadata values at once with the `add_metadata` plugin (@janko)
928
982
 
929
- ## 2.4.1 (2016-10-17)
983
+ ## 2.4.1 (2016-10-17) [[release notes]](https://shrinerb.com/docs/release_notes/2.4.1)
930
984
 
931
985
  * Move back JSON serialization from `Attacher#write` to `Attacher#_set` (@janko)
932
986
 
@@ -936,7 +990,7 @@
936
990
 
937
991
  * In `UploadedFile#download` use extension from `#original_filename` if `#id` doesn't have it (@janko)
938
992
 
939
- ## 2.4.0 (2016-10-11)
993
+ ## 2.4.0 (2016-10-11) [[release notes]](https://shrinerb.com/docs/release_notes/2.4.0)
940
994
 
941
995
  * Add `#convert_before_write` and `#convert_after_read` on the Attacher for data attribute conversion (@janko)
942
996
 
@@ -972,11 +1026,11 @@
972
1026
 
973
1027
  * Override `#to_s` in `Shrine::Attachment` for better introspection with `puts` (@janko)
974
1028
 
975
- ## 2.3.1 (2016-09-01)
1029
+ ## 2.3.1 (2016-09-01) [[release notes]](https://shrinerb.com/docs/release_notes/2.3.1)
976
1030
 
977
1031
  * Don't change permissions of existing directories in FileSystem storage (@janko)
978
1032
 
979
- ## 2.3.0 (2016-08-27)
1033
+ ## 2.3.0 (2016-08-27) [[release notes]](https://shrinerb.com/docs/release_notes/2.3.0)
980
1034
 
981
1035
  * Prevent client from caching the presign response in direct_upload plugin (@janko)
982
1036
 
@@ -1002,7 +1056,7 @@
1002
1056
 
1003
1057
  * Add `:directory_permissions` to `Storage::FileSystem` (@janko)
1004
1058
 
1005
- ## 2.2.0 (2016-07-29)
1059
+ ## 2.2.0 (2016-07-29) [[release notes]](https://shrinerb.com/docs/release_notes/2.2.0)
1006
1060
 
1007
1061
  * Soft deprecate `:phase` over `:action` in `context` (@janko)
1008
1062
 
@@ -1034,11 +1088,11 @@
1034
1088
 
1035
1089
  * Avoid an additional HEAD request to determine content length in multipart S3 copy (@janko)
1036
1090
 
1037
- ## 2.1.1 (2016-07-14)
1091
+ ## 2.1.1 (2016-07-14) [[release notes]](https://shrinerb.com/docs/release_notes/2.1.1)
1038
1092
 
1039
1093
  * Fix `S3#open` throwing a NameError if `net/http` isn't required (@janko)
1040
1094
 
1041
- ## 2.1.0 (2016-06-27)
1095
+ ## 2.1.0 (2016-06-27) [[release notes]](https://shrinerb.com/docs/release_notes/2.1.0)
1042
1096
 
1043
1097
  * Remove `:names` from versions plugin, and deprecate generating versions in :cache phase (@janko)
1044
1098
 
@@ -1054,11 +1108,11 @@
1054
1108
 
1055
1109
  * Deprecate `#cached_<attachment>_data=` over using `<attachment>` for the hidden field (@janko)
1056
1110
 
1057
- ## 2.0.1 (2016-05-30)
1111
+ ## 2.0.1 (2016-05-30) [[release notes]](https://shrinerb.com/docs/release_notes/2.0.1)
1058
1112
 
1059
1113
  * Don't override previously set default_url in versions plugin (@janko)
1060
1114
 
1061
- ## 2.0.0 (2016-05-19)
1115
+ ## 2.0.0 (2016-05-19) [[release notes]](https://shrinerb.com/docs/release_notes/2.0.0)
1062
1116
 
1063
1117
  * Include query parameters in CDN-ed S3 URLs, making them work for private objects (@janko)
1064
1118
 
@@ -1138,17 +1192,17 @@
1138
1192
 
1139
1193
  * Deprecate loading the backgrounding plugin through the old "background_helpers" alias (@janko)
1140
1194
 
1141
- ## 1.4.2 (2016-04-19)
1195
+ ## 1.4.2 (2016-04-19) [[release notes]](https://shrinerb.com/docs/release_notes/1.4.2)
1142
1196
 
1143
1197
  * Removed ActiveRecord's automatic support for optimistic locking as it wasn't stable (@janko)
1144
1198
 
1145
1199
  * Fixed record's dataset being modified after promoting preventing further updates with the same instance (@janko)
1146
1200
 
1147
- ## 1.4.1 (2016-04-18)
1201
+ ## 1.4.1 (2016-04-18) [[release notes]](https://shrinerb.com/docs/release_notes/1.4.1)
1148
1202
 
1149
1203
  * Bring back triggering callbacks on promote in ORM plugins, and add support for optimistic locking (@janko)
1150
1204
 
1151
- ## 1.4.0 (2016-04-15)
1205
+ ## 1.4.0 (2016-04-15) [[release notes]](https://shrinerb.com/docs/release_notes/1.4.0)
1152
1206
 
1153
1207
  * Return "Content-Length" response header in download_endpoint plugin (@janko)
1154
1208
 
@@ -1204,7 +1258,7 @@
1204
1258
 
1205
1259
  * Fix keep_files not to spawn a background job when file will not be deleted (@janko)
1206
1260
 
1207
- ## 1.3.0 (2016-03-12)
1261
+ ## 1.3.0 (2016-03-12) [[release notes]](https://shrinerb.com/docs/release_notes/1.3.0)
1208
1262
 
1209
1263
  * Add `<attachment>_cached?` and `<attachment>_stored?` to migration_helpers plugin (@janko)
1210
1264
 
@@ -1246,7 +1300,7 @@
1246
1300
 
1247
1301
  * Fix `NameError` when silencing "missing record" errors in backgrounding (@janko)
1248
1302
 
1249
- ## 1.2.0 (2016-01-26)
1303
+ ## 1.2.0 (2016-01-26) [[release notes]](https://shrinerb.com/docs/release_notes/1.2.0)
1250
1304
 
1251
1305
  * Make `Shrine::Attacher.promote` and `Shrine::Attacher.delete` return the record in backgrounding plugin (@janko)
1252
1306
 
@@ -1262,7 +1316,7 @@
1262
1316
 
1263
1317
  * Make custom metadata inherited from uploaded files and make `#extract_metadata` called only on caching (@janko)
1264
1318
 
1265
- ## 1.1.0 (2015-12-26)
1319
+ ## 1.1.0 (2015-12-26) [[release notes]](https://shrinerb.com/docs/release_notes/1.1.0)
1266
1320
 
1267
1321
  * Rename the "background_helpers" plugin to "backgrounding" (@janko)
1268
1322
 
@@ -1332,7 +1386,7 @@
1332
1386
 
1333
1387
  * Reduce length of URLs generated with pretty_location plugin (@gshaw)
1334
1388
 
1335
- ## 1.0.0 (2015-11-27)
1389
+ ## 1.0.0 (2015-11-27) [[release notes]](https://shrinerb.com/docs/release_notes/1.0.0)
1336
1390
 
1337
1391
  * Improve Windows compatibility in the FileSystem storage (@janko)
1338
1392
 
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2015-2017 Janko Marohnić
3
+ Copyright (c) 2015-2019 Janko Marohnić
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
data/README.md CHANGED
@@ -1,18 +1,22 @@
1
1
  # [Shrine]
2
2
 
3
+ <img src="https://shrinerb.com/img/logo.png" width="100" alt="Shrine logo: a red paperclip" align="right" />
4
+
3
5
  Shrine is a toolkit for handling file attachments in Ruby applications. Some highlights:
4
6
 
5
7
  * **Modular design** – the [plugin system] allows you to load only the functionality you need
6
8
  * **Memory friendly** – streaming uploads and [downloads][Retrieving Uploads] make it work great with large files
7
9
  * **Cloud storage** – store files on [disk][FileSystem], [AWS S3][S3], [Google Cloud][GCS], [Cloudinary] and others
8
10
  * **Persistence integrations** – works with [Sequel], [ActiveRecord], [ROM], [Hanami] and [Mongoid] and others
9
- * **Flexible processing** – generate thumbnails [up front] or [on-the-fly] using [ImageMagick] or [libvips]
11
+ * **Flexible processing** – generate thumbnails [eagerly] or [on-the-fly] using [ImageMagick] or [libvips]
10
12
  * **Metadata validation** – [validate files][validation] based on [extracted metadata][metadata]
11
13
  * **Direct uploads** – upload asynchronously [to your app][simple upload] or [to the cloud][presigned upload] using [Uppy]
12
14
  * **Resumable uploads** – make large file uploads [resumable][resumable upload] on [S3][uppy-s3_multipart] or [tus][tus-ruby-server]
13
15
  * **Background jobs** – built-in support for [background processing][backgrounding] that supports [any backgrounding library][Backgrounding Libraries]
14
16
 
15
- Please follow along with the **[Getting Started guide]**.
17
+ If you're curious how it compares to other file attachment libraries, see the
18
+ [Advantages of Shrine]. Otherwise, follow along with the **[Getting Started
19
+ guide]**.
16
20
 
17
21
  ## Links
18
22
 
@@ -23,6 +27,91 @@ Please follow along with the **[Getting Started guide]**.
23
27
  | Wiki | [github.com/shrinerb/shrine/wiki](https://github.com/shrinerb/shrine/wiki) |
24
28
  | Help & Discussion | [discourse.shrinerb.com](https://discourse.shrinerb.com) |
25
29
 
30
+ ## Setup
31
+
32
+ Add the gem to your Gemfile:
33
+
34
+ ```rb
35
+ # Gemfile
36
+ gem "shrine", "~> 3.0"
37
+ ```
38
+
39
+ Then add `config/initializers/shrine.rb` which sets up the storage and loads
40
+ ORM integration:
41
+
42
+ ```rb
43
+ require "shrine"
44
+ require "shrine/storage/file_system"
45
+
46
+ Shrine.storages = {
47
+ cache: Shrine::Storage::FileSystem.new("public", prefix: "uploads/cache"), # temporary
48
+ store: Shrine::Storage::FileSystem.new("public", prefix: "uploads"), # permanent
49
+ }
50
+
51
+ Shrine.plugin :activerecord # loads Active Record integration
52
+ Shrine.plugin :cached_attachment_data # enables retaining cached file across form redisplays
53
+ Shrine.plugin :restore_cached_data # extracts metadata for assigned cached files
54
+ ```
55
+
56
+ Next, add the `<name>_data` column to the table you want to attach files to. For
57
+ an "image" attachment on a `photos` table this would be an `image_data` column:
58
+
59
+ ```
60
+ $ rails generate migration add_image_data_to_photos image_data:text
61
+ ```
62
+
63
+ Now create an uploader class (which you can put in `app/uploaders`) and
64
+ register the attachment on your model:
65
+
66
+ ```rb
67
+ class ImageUploader < Shrine
68
+ # plugins and uploading logic
69
+ end
70
+ ```
71
+ ```rb
72
+ class Photo < ActiveRecord::Base
73
+ include ImageUploader::Attachment(:image) # adds an `image` virtual attribute
74
+ end
75
+ ```
76
+
77
+ In our views let's now add form fields for our attachment attribute that will
78
+ allow users to upload files:
79
+
80
+ ```erb
81
+ <%= form_for @photo do |f| %>
82
+ <%= f.hidden_field :image, value: @photo.cached_image_data %>
83
+ <%= f.file_field :image %>
84
+ <%= f.submit %>
85
+ <% end %>
86
+ ```
87
+
88
+ When the form is submitted, in your controller you can assign the file from
89
+ request params to the attachment attribute on the model:
90
+
91
+ ```rb
92
+ class PhotosController < ApplicationController
93
+ def create
94
+ Photo.create(photo_params) # attaches the uploaded file
95
+ # ...
96
+ end
97
+
98
+ private
99
+
100
+ def photo_params
101
+ params.require(:photo).permit(:image)
102
+ end
103
+ end
104
+ ```
105
+
106
+ Once a file is uploaded and attached to the record, you can retrieve the file
107
+ URL and display it on the page:
108
+
109
+ ```erb
110
+ <%= image_tag @photo.image_url %>
111
+ ```
112
+
113
+ See the **[Getting Started guide]** for further documentation.
114
+
26
115
  ## Inspiration
27
116
 
28
117
  Shrine was heavily inspired by [Refile] and [Roda]. From Refile it borrows the
@@ -48,6 +137,7 @@ mailing lists is expected to follow the [Shrine code of conduct][CoC].
48
137
  The gem is available as open source under the terms of the [MIT License].
49
138
 
50
139
  [Shrine]: https://shrinerb.com
140
+ [Advantages of Shrine]: https://shrinerb.com/docs/advantages
51
141
  [plugin system]: https://shrinerb.com/docs/getting-started#plugin-system
52
142
  [Retrieving Uploads]: https://shrinerb.com/docs/retrieving-uploads
53
143
  [FileSystem]: https://shrinerb.com/docs/storage/file-system
@@ -59,8 +149,8 @@ The gem is available as open source under the terms of the [MIT License].
59
149
  [ROM]: https://github.com/shrinerb/shrine-rom
60
150
  [Hanami]: https://github.com/katafrakt/hanami-shrine
61
151
  [Mongoid]: https://github.com/shrinerb/shrine-mongoid
62
- [up front]: https://shrinerb.com/docs/getting-started#processing-up-front
63
- [on-the-fly]: https://shrinerb.com/docs/getting-started#processing-on-the-fly
152
+ [eagerly]: https://shrinerb.com/docs/getting-started#eager-processing
153
+ [on-the-fly]: https://shrinerb.com/docs/getting-started#on-the-fly-processing
64
154
  [ImageMagick]: https://github.com/janko/image_processing/blob/master/doc/minimagick.md#readme
65
155
  [libvips]: https://github.com/janko/image_processing/blob/master/doc/vips.md#readme
66
156
  [validation]: https://shrinerb.com/docs/validation