title: Shrine 3.2.0

New features

rb # Gemfile gem "mini_mime" # default dependency of type_predicates rb Shrine.plugin :type_predicates

The plugin adds four predicate methods based on the general type of the file:

rb file.image? # returns true for any "image/*" MIME type file.video? # returns true for any "video/*" MIME type file.audio? # returns true for any "audio/*" MIME type file.text? # returns true for any "text/*" MIME type

You can also check for specific MIME type using the extension name:

rb file.type?(:jpg) # returns true if MIME type is "image/jpeg" file.type?(:svg) # returns true if MIME type is "image/svg+xml" file.type?(:mov) # returns true if MIME type is "video/quicktime" file.type?(:ppt) # returns true if MIME type is "application/vnd.ms-powerpoint" ...

For convenience, you can create predicate methods for specific file types:

rb Shrine.plugin :type_predicates, methods: %i[jpg svg mov ppt] rb file.jpg? # returns true if MIME type is "image/jpeg" file.svg? # returns true if MIME type is "image/svg+xml" file.mov? # returns true if MIME type is "video/quicktime" file.ppt? # returns true if MIME type is "application/vnd.ms-powerpoint"

rb attacher.file.metadata #=> { ... } attacher.add_metadata("foo" => "bar") attacher.file.metadata #=> { ..., "foo" => "bar" }

Other improvements

rb photo.image #=> #<Shrine::UploadedFile id="foo" storage=:store metadata={...}> photo.image = { "id" => "foo", "storage" => "store", "metadata" => { ... } } # no-op

This allows treating the attachment attribute as a persistent attribute, where the current value can be assigned back on record updates.

Backwards compatibility

rb photo.image #=> #<Shrine::UploadedFile id="foo" storage=:cache metadata={...}> photo.image = { "id" => "foo", "storage" => "cache", "metadata" => { ... } } # no-op