shrine 2.14.0 → 2.15.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 (149) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +384 -374
  3. data/README.md +132 -63
  4. data/doc/advantages.md +191 -109
  5. data/doc/attacher.md +1 -1
  6. data/doc/carrierwave.md +4 -4
  7. data/doc/creating_storages.md +2 -2
  8. data/doc/design.md +2 -2
  9. data/doc/direct_s3.md +3 -3
  10. data/doc/metadata.md +1 -1
  11. data/doc/multiple_files.md +2 -2
  12. data/doc/paperclip.md +3 -3
  13. data/doc/plugins/activerecord.md +92 -0
  14. data/doc/plugins/add_metadata.md +93 -0
  15. data/doc/plugins/backgrounding.md +148 -0
  16. data/doc/plugins/backup.md +29 -0
  17. data/doc/plugins/cached_attachment_data.md +23 -0
  18. data/doc/plugins/copy.md +22 -0
  19. data/doc/plugins/data_uri.md +92 -0
  20. data/doc/plugins/default_storage.md +16 -0
  21. data/doc/plugins/default_url.md +33 -0
  22. data/doc/plugins/default_url_options.md +22 -0
  23. data/doc/plugins/delete_promoted.md +10 -0
  24. data/doc/plugins/delete_raw.md +16 -0
  25. data/doc/plugins/derivation_endpoint.md +747 -0
  26. data/doc/plugins/determine_mime_type.md +64 -0
  27. data/doc/plugins/direct_upload.md +170 -0
  28. data/doc/plugins/download_endpoint.md +83 -0
  29. data/doc/plugins/dynamic_storage.md +20 -0
  30. data/doc/plugins/hooks.md +56 -0
  31. data/doc/plugins/included.md +15 -0
  32. data/doc/plugins/infer_extension.md +57 -0
  33. data/doc/plugins/keep_files.md +20 -0
  34. data/doc/plugins/logging.md +39 -0
  35. data/doc/plugins/metadata_attribues.md +43 -0
  36. data/doc/plugins/migration_helpers.md +58 -0
  37. data/doc/plugins/module_include.md +40 -0
  38. data/doc/plugins/moving.md +17 -0
  39. data/doc/plugins/multi_delete.md +18 -0
  40. data/doc/plugins/parallelize.md +14 -0
  41. data/doc/plugins/parsed_json.md +9 -0
  42. data/doc/plugins/presign_endpoint.md +133 -0
  43. data/doc/plugins/pretty_location.md +29 -0
  44. data/doc/plugins/processing.md +68 -0
  45. data/doc/plugins/rack_file.md +49 -0
  46. data/doc/plugins/rack_response.md +96 -0
  47. data/doc/plugins/recache.md +27 -0
  48. data/doc/plugins/refresh_metadata.md +31 -0
  49. data/doc/plugins/remote_url.md +104 -0
  50. data/doc/plugins/remove_attachment.md +16 -0
  51. data/doc/plugins/remove_invalid.md +9 -0
  52. data/doc/plugins/restore_cached_data.md +14 -0
  53. data/doc/plugins/sequel.md +64 -0
  54. data/doc/plugins/signature.md +49 -0
  55. data/doc/plugins/store_dimensions.md +68 -0
  56. data/doc/plugins/tempfile.md +40 -0
  57. data/doc/plugins/upload_endpoint.md +123 -0
  58. data/doc/plugins/upload_options.md +28 -0
  59. data/doc/plugins/validation_helpers.md +129 -0
  60. data/doc/plugins/versions.md +179 -0
  61. data/doc/processing.md +217 -247
  62. data/doc/refile.md +3 -3
  63. data/doc/release_notes/1.0.0.md +143 -0
  64. data/doc/release_notes/1.1.0.md +184 -0
  65. data/doc/release_notes/1.2.0.md +37 -0
  66. data/doc/release_notes/1.3.0.md +90 -0
  67. data/doc/release_notes/1.4.0.md +167 -0
  68. data/doc/release_notes/1.4.1.md +9 -0
  69. data/doc/release_notes/1.4.2.md +20 -0
  70. data/doc/release_notes/2.0.0.md +173 -0
  71. data/doc/release_notes/2.0.1.md +12 -0
  72. data/doc/release_notes/2.1.0.md +59 -0
  73. data/doc/release_notes/2.1.1.md +8 -0
  74. data/doc/release_notes/2.10.0.md +52 -0
  75. data/doc/release_notes/2.10.1.md +6 -0
  76. data/doc/release_notes/2.11.0.md +69 -0
  77. data/doc/release_notes/2.12.0.md +65 -0
  78. data/doc/release_notes/2.13.0.md +146 -0
  79. data/doc/release_notes/2.14.0.md +278 -0
  80. data/doc/release_notes/2.15.0.md +82 -0
  81. data/doc/release_notes/2.2.0.md +98 -0
  82. data/doc/release_notes/2.3.0.md +50 -0
  83. data/doc/release_notes/2.3.1.md +10 -0
  84. data/doc/release_notes/2.4.0.md +87 -0
  85. data/doc/release_notes/2.4.1.md +29 -0
  86. data/doc/release_notes/2.5.0.md +130 -0
  87. data/doc/release_notes/2.6.0.md +254 -0
  88. data/doc/release_notes/2.6.1.md +14 -0
  89. data/doc/release_notes/2.7.0.md +180 -0
  90. data/doc/release_notes/2.8.0.md +95 -0
  91. data/doc/release_notes/2.9.0.md +82 -0
  92. data/doc/retrieving_uploads.md +1 -1
  93. data/doc/storage/file_system.md +96 -0
  94. data/doc/storage/s3.md +293 -0
  95. data/doc/validation.md +1 -1
  96. data/lib/shrine/plugins/_urlsafe_serialization.rb +33 -125
  97. data/lib/shrine/plugins/activerecord.rb +0 -78
  98. data/lib/shrine/plugins/add_metadata.rb +0 -80
  99. data/lib/shrine/plugins/backgrounding.rb +0 -134
  100. data/lib/shrine/plugins/backup.rb +0 -22
  101. data/lib/shrine/plugins/cached_attachment_data.rb +0 -15
  102. data/lib/shrine/plugins/copy.rb +0 -14
  103. data/lib/shrine/plugins/data_uri.rb +0 -73
  104. data/lib/shrine/plugins/default_storage.rb +0 -11
  105. data/lib/shrine/plugins/default_url.rb +0 -25
  106. data/lib/shrine/plugins/default_url_options.rb +0 -16
  107. data/lib/shrine/plugins/delete_promoted.rb +0 -6
  108. data/lib/shrine/plugins/delete_raw.rb +0 -10
  109. data/lib/shrine/plugins/derivation_endpoint.rb +652 -0
  110. data/lib/shrine/plugins/determine_mime_type.rb +1 -85
  111. data/lib/shrine/plugins/direct_upload.rb +0 -155
  112. data/lib/shrine/plugins/download_endpoint.rb +11 -73
  113. data/lib/shrine/plugins/dynamic_storage.rb +0 -17
  114. data/lib/shrine/plugins/hooks.rb +0 -48
  115. data/lib/shrine/plugins/included.rb +0 -12
  116. data/lib/shrine/plugins/infer_extension.rb +0 -49
  117. data/lib/shrine/plugins/keep_files.rb +0 -19
  118. data/lib/shrine/plugins/logging.rb +0 -39
  119. data/lib/shrine/plugins/metadata_attributes.rb +0 -35
  120. data/lib/shrine/plugins/migration_helpers.rb +0 -50
  121. data/lib/shrine/plugins/module_include.rb +0 -32
  122. data/lib/shrine/plugins/moving.rb +0 -12
  123. data/lib/shrine/plugins/multi_delete.rb +0 -13
  124. data/lib/shrine/plugins/parallelize.rb +0 -8
  125. data/lib/shrine/plugins/parsed_json.rb +0 -5
  126. data/lib/shrine/plugins/presign_endpoint.rb +2 -117
  127. data/lib/shrine/plugins/pretty_location.rb +0 -22
  128. data/lib/shrine/plugins/processing.rb +0 -55
  129. data/lib/shrine/plugins/rack_file.rb +0 -39
  130. data/lib/shrine/plugins/rack_response.rb +0 -81
  131. data/lib/shrine/plugins/recache.rb +0 -21
  132. data/lib/shrine/plugins/refresh_metadata.rb +0 -24
  133. data/lib/shrine/plugins/remote_url.rb +0 -85
  134. data/lib/shrine/plugins/remove_attachment.rb +0 -10
  135. data/lib/shrine/plugins/remove_invalid.rb +0 -6
  136. data/lib/shrine/plugins/restore_cached_data.rb +0 -10
  137. data/lib/shrine/plugins/sequel.rb +0 -54
  138. data/lib/shrine/plugins/signature.rb +0 -37
  139. data/lib/shrine/plugins/store_dimensions.rb +0 -63
  140. data/lib/shrine/plugins/tempfile.rb +4 -35
  141. data/lib/shrine/plugins/upload_endpoint.rb +2 -109
  142. data/lib/shrine/plugins/upload_options.rb +0 -20
  143. data/lib/shrine/plugins/validation_helpers.rb +0 -36
  144. data/lib/shrine/plugins/versions.rb +0 -156
  145. data/lib/shrine/storage/file_system.rb +0 -77
  146. data/lib/shrine/storage/s3.rb +0 -249
  147. data/lib/shrine/version.rb +1 -1
  148. data/shrine.gemspec +2 -2
  149. metadata +86 -6
@@ -2,28 +2,6 @@
2
2
 
3
3
  class Shrine
4
4
  module Plugins
5
- # The `pretty_location` plugin attempts to generate a nicer folder structure
6
- # for uploaded files.
7
- #
8
- # plugin :pretty_location
9
- #
10
- # This plugin uses the context information from the Attacher to try to
11
- # generate a nested folder structure which separates files for each record.
12
- # The newly generated locations will typically look like this:
13
- #
14
- # "user/564/avatar/thumb-493g82jf23.jpg"
15
- # # :model/:id/:attachment/:version-:uid.:extension
16
- #
17
- # By default if a record class is inside a namespace, only the "inner"
18
- # class name is used in the location. If you want to include the namespace,
19
- # you can pass in the `:namespace` option with the desired separator as the
20
- # value:
21
- #
22
- # plugin :pretty_location, namespace: "_"
23
- # # "blog_user/.../493g82jf23.jpg"
24
- #
25
- # plugin :pretty_location, namespace: "/"
26
- # # "blog/user/.../493g82jf23.jpg"
27
5
  module PrettyLocation
28
6
  def self.configure(uploader, opts = {})
29
7
  uploader.opts[:pretty_location_namespace] = opts.fetch(:namespace, uploader.opts[:pretty_location_namespace])
@@ -2,61 +2,6 @@
2
2
 
3
3
  class Shrine
4
4
  module Plugins
5
- # Shrine uploaders can define the `#process` method, which will get called
6
- # whenever a file is uploaded. It is given the original file, and is
7
- # expected to return the processed files.
8
- #
9
- # def process(io, context)
10
- # # you can process the original file `io` and return processed file(s)
11
- # end
12
- #
13
- # However, when handling files as attachments, the same file is uploaded
14
- # to temporary and permanent storage. Since we only want to apply the same
15
- # processing once, we need to branch based on the context.
16
- #
17
- # def process(io, context)
18
- # if context[:action] == :store # promote phase
19
- # # ...
20
- # end
21
- # end
22
- #
23
- # The `processing` plugin simplifies this by allowing us to declaratively
24
- # define file processing for specified actions.
25
- #
26
- # plugin :processing
27
- #
28
- # process(:store) do |io, context|
29
- # # ...
30
- # end
31
- #
32
- # An example of resizing an image using the [image_processing] library:
33
- #
34
- # require "image_processing/mini_magick"
35
- #
36
- # process(:store) do |io, context|
37
- # io.download do |original|
38
- # ImageProcessing::MiniMagick
39
- # .source(original)
40
- # .resize_to_limit!(800, 800)
41
- # end
42
- # end
43
- #
44
- # The declarations are additive and inheritable, so for the same action you
45
- # can declare multiple blocks, and they will be performed in the same order,
46
- # with output from previous block being the input to next.
47
- #
48
- # ## Manually Run Processing
49
- #
50
- # You can manually trigger the defined processing via the uploader by calling
51
- # `#upload` or `#process` and setting `:action` to the name of your processing block:
52
- #
53
- # uploader.upload(file, action: :store) # process and upload
54
- # uploader.process(file, action: :store) # only process
55
- #
56
- # If you want the result of processing to be multiple files, use the
57
- # `versions` plugin.
58
- #
59
- # [image_processing]: https://github.com/janko-m/image_processing
60
5
  module Processing
61
6
  def self.configure(uploader)
62
7
  uploader.opts[:processing] ||= {}
@@ -4,45 +4,6 @@ require "forwardable"
4
4
 
5
5
  class Shrine
6
6
  module Plugins
7
- # The `rack_file` plugin enables uploaders to accept Rack uploaded file
8
- # hashes for uploading.
9
- #
10
- # plugin :rack_file
11
- #
12
- # When a file is uploaded to your Rack application using the
13
- # `multipart/form-data` parameter encoding, Rack converts the uploaded file
14
- # to a hash.
15
- #
16
- # file_hash #=>
17
- # # {
18
- # # :name => "file",
19
- # # :filename => "cats.png",
20
- # # :type => "image/png",
21
- # # :tempfile => #<Tempfile:/var/folders/3n/3asd/-Tmp-/RackMultipart201-1476-nfw2-0>,
22
- # # :head => "Content-Disposition: form-data; ...",
23
- # # }
24
- #
25
- # Since Shrine only accepts IO objects, you would normally need to fetch
26
- # the `:tempfile` object and pass it directly. This plugin enables the
27
- # attacher to accept the Rack uploaded file hash directly, which is
28
- # convenient when doing mass attribute assignment.
29
- #
30
- # user.avatar = file_hash
31
- # # or
32
- # attacher.assign(file_hash)
33
- #
34
- # Internally the Rack uploaded file hash will be converted into an IO
35
- # object using `Shrine.rack_file`, which you can also use directly:
36
- #
37
- # # or YourUploader.rack_file(file_hash)
38
- # io = Shrine.rack_file(file_hash)
39
- # io.original_filename #=> "cats.png"
40
- # io.content_type #=> "image/png"
41
- # io.size #=> 58342
42
- #
43
- # Note that this plugin is not needed in Rails applications, as Rails
44
- # already wraps the Rack uploaded file hash into an
45
- # `ActionDispatch::Http::UploadedFile` object.
46
7
  module RackFile
47
8
  module ClassMethods
48
9
  # Accepts a Rack uploaded file hash and wraps it in an IO object.
@@ -5,87 +5,6 @@ require "content_disposition"
5
5
 
6
6
  class Shrine
7
7
  module Plugins
8
- # The `rack_response` plugin allows you to convert an `UploadedFile` object
9
- # into a triple consisting of status, headers, and body, suitable for
10
- # returning as a response in a Rack-based application.
11
- #
12
- # plugin :rack_response
13
- #
14
- # To convert a `Shrine::UploadedFile` into a Rack response, simply call
15
- # `#to_rack_response`:
16
- #
17
- # status, headers, body = uploaded_file.to_rack_response
18
- # status #=> 200
19
- # headers #=>
20
- # # {
21
- # # "Content-Length" => "100",
22
- # # "Content-Type" => "text/plain",
23
- # # "Content-Disposition" => "inline; filename=\"file.txt\"",
24
- # # "Accept-Ranges" => "bytes"
25
- # # }
26
- # body # object that responds to #each and #close
27
- #
28
- # An example how this can be used in a Rails controller:
29
- #
30
- # class FilesController < ActionController::Base
31
- # def download
32
- # # ...
33
- # set_rack_response record.attachment.to_rack_response
34
- # end
35
- #
36
- # private
37
- #
38
- # def set_rack_response((status, headers, body))
39
- # self.status = status
40
- # self.headers.merge!(headers)
41
- # self.response_body = body
42
- # end
43
- # end
44
- #
45
- # The `#each` method on the response body object will stream the uploaded
46
- # file directly from the storage. It also works with [Rack::Sendfile] when
47
- # using `FileSystem` storage.
48
- #
49
- # ## Type
50
- #
51
- # The response `Content-Type` header will default to the value of the
52
- # `mime_type` metadata. A custom content type can be provided via the
53
- # `:type` option:
54
- #
55
- # _, headers, _ uploaded_file.to_rack_response(type: "text/plain; charset=utf-8")
56
- # headers["Content-Type"] #=> "text/plain; charset=utf-8"
57
- #
58
- # ## Filename
59
- #
60
- # The download filename in the `Content-Disposition` header will default to
61
- # the value of the `filename` metadata. A custom download filename can be
62
- # provided via the `:filename` option:
63
- #
64
- # _, headers, _ uploaded_file.to_rack_response(filename: "my-filename.txt")
65
- # headers["Content-Disposition"] #=> "inline; filename=\"my-filename.txt\""
66
- #
67
- # ## Disposition
68
- #
69
- # The default disposition in the "Content-Disposition" header is `inline`,
70
- # but it can be changed via the `:disposition` option:
71
- #
72
- # _, headers, _ = uploaded_file.to_rack_response(disposition: "attachment")
73
- # headers["Content-Disposition"] #=> "attachment; filename=\"file.txt\""
74
- #
75
- # ## Range
76
- #
77
- # [Partial responses][range requests] are also supported via the `:range`
78
- # option, which accepts a value of the `Range` request header.
79
- #
80
- # env["HTTP_RANGE"] #=> "bytes=100-200"
81
- # status, headers, body = uploaded_file.to_rack_response(range: env["HTTP_RANGE"])
82
- # status #=> 206
83
- # headers["Content-Length"] #=> "101"
84
- # headers["Content-Range"] #=> "bytes 100-200/1000"
85
- # body # partial content
86
- #
87
- # [range requests]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Range_requests
88
- # [Rack::Sendfile]: https://www.rubydoc.info/github/rack/rack/Rack/Sendfile
89
8
  module RackResponse
90
9
  module FileMethods
91
10
  # Returns a Rack response triple for the uploaded file.
@@ -2,27 +2,6 @@
2
2
 
3
3
  class Shrine
4
4
  module Plugins
5
- # The `recache` plugin allows you to process your attachment after
6
- # validations succeed, but before the attachment is promoted. This is
7
- # useful for example when you want to generate some versions upfront (so
8
- # the user immediately sees them) and other versions you want to generate
9
- # in the promotion phase in a background job.
10
- #
11
- # plugin :recache
12
- # plugin :processing
13
- #
14
- # process(:recache) do |io, context|
15
- # # perform cheap processing
16
- # end
17
- #
18
- # process(:store) do |io, context|
19
- # # perform more expensive processing
20
- # end
21
- #
22
- # Recaching will be automatically triggered in a "before save" callback,
23
- # but if you're using the attacher directly, you can call it manually:
24
- #
25
- # attacher.recache if attacher.changed?
26
5
  module Recache
27
6
  module AttacherMethods
28
7
  def save
@@ -2,30 +2,6 @@
2
2
 
3
3
  class Shrine
4
4
  module Plugins
5
- # The `refresh_metadata` plugin allows you to re-extract metadata from an
6
- # uploaded file.
7
- #
8
- # plugin :refresh_metadata
9
- #
10
- # It provides `UploadedFile#refresh_metadata!` method, which triggers
11
- # metadata extraction (calls `Shrine#extract_metadata`) with the uploaded
12
- # file opened for reading, and updates the existing metadata hash with the
13
- # results.
14
- #
15
- # uploaded_file.refresh_metadata!
16
- # uploaded_file.metadata # re-extracted metadata
17
- #
18
- # For remote storages this will make an HTTP request to open the file for
19
- # reading, but only the portion of the file needed for extracting each
20
- # metadata value will be downloaded.
21
- #
22
- # If the uploaded file is already open, it is passed to metadata extraction
23
- # as is.
24
- #
25
- # uploaded_file.open do
26
- # uploaded_file.refresh_metadata!
27
- # # ...
28
- # end
29
5
  module RefreshMetadata
30
6
  module FileMethods
31
7
  def refresh_metadata!(context = {})
@@ -4,91 +4,6 @@ require "down"
4
4
 
5
5
  class Shrine
6
6
  module Plugins
7
- # The `remote_url` plugin allows you to attach files from a remote location.
8
- #
9
- # plugin :remote_url, max_size: 20*1024*1024
10
- #
11
- # If for example your attachment is called "avatar", this plugin will add
12
- # `#avatar_remote_url` and `#avatar_remote_url=` methods to your model.
13
- #
14
- # user.avatar #=> nil
15
- # user.avatar_remote_url = "http://example.com/cool-image.png"
16
- # user.avatar #=> #<Shrine::UploadedFile>
17
- #
18
- # user.avatar.mime_type #=> "image/png"
19
- # user.avatar.size #=> 43423
20
- # user.avatar.original_filename #=> "cool-image.png"
21
- #
22
- # You can also use `#remote_url=` and `#remote_url` methods directly on the
23
- # `Shrine::Attacher`:
24
- #
25
- # attacher.remote_url = "http://example.com/cool-image.png"
26
- #
27
- # The file will by default be downloaded using [Down], which is a wrapper
28
- # around the `open-uri` standard library. Note that Down expects the given
29
- # URL to be URI-encoded.
30
- #
31
- # ## Dynamic options
32
- #
33
- # You can dynamically pass options to the downloader by using
34
- # `Attacher#assign_remote_url`:
35
- #
36
- # attacher.assign_remote_url("http://example.com/cool-image.png", downloader: { 'Authorization' => 'Basic ...' })
37
- #
38
- # ## Maximum size
39
- #
40
- # It's a good practice to limit the maximum filesize of the remote file:
41
- #
42
- # plugin :remote_url, max_size: 20*1024*1024 # 20 MB
43
- #
44
- # Now if a file that is bigger than 20MB is assigned, download will be
45
- # terminated as soon as it gets the "Content-Length" header, or the
46
- # size of currently downloaded content surpasses the maximum size.
47
- # However, if for whatever reason you don't want to limit the maximum file
48
- # size, you can set `:max_size` to nil:
49
- #
50
- # plugin :remote_url, max_size: nil
51
- #
52
- # ## Custom downloader
53
- #
54
- # If you want to customize how the file is downloaded, you can override the
55
- # `:downloader` parameter and provide your own implementation. For example,
56
- # you can use the HTTP.rb Down backend for downloading:
57
- #
58
- # require "down/http"
59
- #
60
- # plugin :remote_url, max_size: 20*1024*1024, downloader: -> (url, max_size:, **options) do
61
- # Down::Http.download(url, max_size: max_size, **options) do |http|
62
- # http.follow(max_hops: 2).timeout(connect: 2, read: 2)
63
- # end
64
- # end
65
- #
66
- # ## Errors
67
- #
68
- # If download errors, the error is rescued and a validation error is added
69
- # equal to the error message. You can change the default error message:
70
- #
71
- # plugin :remote_url, error_message: "download failed"
72
- # plugin :remote_url, error_message: -> (url, error) { I18n.t("errors.download_failed") }
73
- #
74
- # ## Background
75
- #
76
- # If you want the file to be downloaded from the URL in the background, you
77
- # can use the [shrine-url] storage which allows you to assign a custom URL
78
- # as cached file ID, and pair that with the `backgrounding` plugin.
79
- #
80
- # ## File extension
81
- #
82
- # When attaching from a remote URL, the uploaded file location will have
83
- # the extension inferred from the URL. However, some URLs might not have an
84
- # extension, in which case the uploaded file location also won't have the
85
- # extension. If you want the upload location to always have an extension,
86
- # you can load the `infer_extension` plugin to infer it from the MIME type.
87
- #
88
- # plugin :infer_extension
89
- #
90
- # [Down]: https://github.com/janko-m/down
91
- # [shrine-url]: https://github.com/shrinerb/shrine-url
92
7
  module RemoteUrl
93
8
  def self.configure(uploader, opts = {})
94
9
  raise Error, "The :max_size option is required for remote_url plugin" if !opts.key?(:max_size) && !uploader.opts.key?(:remote_url_max_size)
@@ -2,16 +2,6 @@
2
2
 
3
3
  class Shrine
4
4
  module Plugins
5
- # The `remove_attachment` plugin allows you to delete attachments through
6
- # checkboxes on the web form.
7
- #
8
- # plugin :remove_attachment
9
- #
10
- # If for example your attachment is called "avatar", this plugin will add
11
- # `#remove_avatar` and `#remove_avatar=` methods to your model. This allows
12
- # you to add a form field for removing attachments:
13
- #
14
- # form.check_box :remove_avatar
15
5
  module RemoveAttachment
16
6
  module AttachmentMethods
17
7
  def initialize(*)
@@ -2,12 +2,6 @@
2
2
 
3
3
  class Shrine
4
4
  module Plugins
5
- # The `remove_invalid` plugin automatically deletes a new assigned file if
6
- # it was invalid and deassigns it from the record. If there was a previous
7
- # file attached, it will be assigned back, otherwise no attachment will be
8
- # assigned.
9
- #
10
- # plugin :remove_invalid
11
5
  module RemoveInvalid
12
6
  module AttacherMethods
13
7
  def validate
@@ -2,16 +2,6 @@
2
2
 
3
3
  class Shrine
4
4
  module Plugins
5
- # The `restore_cached_data` plugin re-extracts metadata when assigning
6
- # already cached files, i.e. when the attachment has been retained on
7
- # validation errors or assigned from a direct upload. In both cases you may
8
- # want to re-extract metadata on the server side, mainly to prevent
9
- # tempering, but also in case of direct uploads to obtain metadata that
10
- # couldn't be extracted on the client side.
11
- #
12
- # plugin :restore_cached_data
13
- #
14
- # It uses the `refresh_metadata` plugin to re-extract metadata.
15
5
  module RestoreCachedData
16
6
  def self.load_dependencies(uploader, *)
17
7
  uploader.plugin :refresh_metadata
@@ -4,60 +4,6 @@ require "sequel"
4
4
 
5
5
  class Shrine
6
6
  module Plugins
7
- # The `sequel` plugin extends the "attachment" interface with support for
8
- # Sequel.
9
- #
10
- # plugin :sequel
11
- #
12
- # ## Callbacks
13
- #
14
- # Now the attachment module will add additional callbacks to the model:
15
- #
16
- # * "before save" -- Used by the `recache` plugin.
17
- # * "after commit" (save) -- Promotes the attachment, deletes replaced ones.
18
- # * "after commit" (destroy) -- Deletes the attachment.
19
- #
20
- # If you want to put promoting/deleting into a background job, see the
21
- # `backgrounding` plugin.
22
- #
23
- # Since attaching first saves the record with a cached attachment, then
24
- # saves again with a stored attachment, you can detect this in callbacks:
25
- #
26
- # class User < Sequel::Model
27
- # include ImageUploader::Attachment.new(:avatar)
28
- #
29
- # def before_save
30
- # super
31
- #
32
- # if changed_columns.include?(:avatar) && avatar_attacher.cached?
33
- # # cached
34
- # elsif changed_columns.include?(:avatar) && avatar_attacher.stored?
35
- # # promoted
36
- # end
37
- # end
38
- # end
39
- #
40
- # If you don't want the attachment module to add any callbacks to the
41
- # model, and would instead prefer to call these actions manually, you can
42
- # disable callbacks:
43
- #
44
- # plugin :sequel, callbacks: false
45
- #
46
- # ## Validations
47
- #
48
- # Additionally, any Shrine validation errors will added to Sequel's
49
- # errors upon validation. Note that if you want to validate presence of the
50
- # attachment, you can do it directly on the model.
51
- #
52
- # class User < Sequel::Model
53
- # include ImageUploader::Attachment.new(:avatar)
54
- # validates_presence_of :avatar
55
- # end
56
- #
57
- # If don't want the attachment module to merge file validations errors into
58
- # model errors, you can disable it:
59
- #
60
- # plugin :sequel, validations: false
61
7
  module Sequel
62
8
  def self.configure(uploader, opts = {})
63
9
  uploader.opts[:sequel_callbacks] = opts.fetch(:callbacks, uploader.opts.fetch(:sequel_callbacks, true))