—
title: Shrine 3.7.0
New features
-
The
download_endpointplugin now supports expiring URLs. Configure asecret_keyand optionally a defaultexpires_inon the plugin, then passexpires_in:when generating a URL. The URL is signed with HMAC-SHA256, and the endpoint will reject requests with an expired or tampered signature.
rb plugin :download_endpoint, prefix: "downloads", secret_key: "<your-secret-key>", expires_in: 5 * 60 # optional default; can be overridden per URL
rb uploaded_file.download_url # uses the default expires_in uploaded_file.download_url(expires_in: 10 * 60) # override per URL # => "https://example.com/downloads/<token>?signature=...&expires_at=..."
-
The
derivativesplugin now accepts a:keep_derivativesoption. When set totrue, existing derivatives are kept when a new file is attached viaAttacher#change, instead of being cleared.
rb plugin :derivatives, keep_derivatives: true
rb attacher.derivatives #=> { thumb: #<Shrine::UploadedFile> } attacher.change(new_file) attacher.derivatives #=> { thumb: #<Shrine::UploadedFile> } # preserved
-
The
refresh_metadataplugin now accepts areplace:keyword argument onrefresh_metadata!. Passingreplace: truereplaces the file’s metadata entirely with the freshly extracted values, instead of merging them. This is useful when you want to remove stale custom metadata keys.
“‘rb uploaded_file.metadata[“custom”] = “stale value”
uploaded_file.refresh_metadata! # merge (default) uploaded_file.metadata[“custom”] #=> “stale value” (preserved)
uploaded_file.refresh_metadata!(replace: true) # replace uploaded_file.metadata[“custom”] #=> nil (removed) “‘
Other improvements
-
The
s3storage now prefers usingTransferManager#upload_streamover the deprecated#upload_streammethod on the S3 object, whenTransferManageris available. This avoids deprecation warnings from newer versions of the AWS SDK. -
The
columnplugin no longer attempts to deserialize an empty string as JSON. Previously this would raise a parse error; now the attachment is treated as blank. -
The
backgroundingplugin now correctly forwards keyword arguments passed toAttacher#promote_cachedinto thepromote_blockcallback.
“‘rb Shrine::Attacher.promote_block do |attacher:, my_option:, **| # my_option was previously not forwarded here SomePromoteJob.perform_async(attacher.dump, my_option: my_option) end
attacher.promote_cached(my_option: “value”) # now forwarded correctly “‘
-
UploadedFileno longer produces URI default parser warnings (URI::RFC3986_PARSER.make_regexp is obsolete) when verbose warnings are enabled.
Backwards compatibility
-
Support for Ruby versions below 3.2 has been dropped. Ruby >= 3.2 is now required.
-
ImageProcessing 2.0 made
mini_magickandruby-vipssoft dependencies that are no longer loaded automatically. If you use either gem for image processing, you will need to add it explicitly to yourGemfile:
rb gem "mini_magick" # or gem "ruby-vips"