Class: Alchemy::PictureThumb::Create

Inherits:
Object
  • Object
show all
Defined in:
app/models/alchemy/picture_thumb/create.rb

Overview

Creates a Alchemy::PictureThumb

Stores the processes result of a Alchemy::PictureVariant in the configured Alchemy::PictureThumb.storage_class (Default: FileStore)

Class Method Summary collapse

Class Method Details

.call(variant, signature, uid) ⇒ Alchemy::PictureThumb

Returns The persisted thumbnail record.

Parameters:

  • variant (Alchemy::PictureVariant)

    the to be rendered image

  • signature (String)

    A unique hashed version of the rendering options

  • uid (String)

    The Unique Image Identifier the image is stored at

Returns:



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'app/models/alchemy/picture_thumb/create.rb', line 19

def call(variant, signature, uid)
  return if !variant.picture.valid?

  # create the thumb before storing
  # to prevent db race conditions
  @thumb = Alchemy::PictureThumb.create_or_find_by!(signature: signature) do |thumb|
    thumb.picture = variant.picture
    thumb.uid = uid
  end
  begin
    Alchemy::PictureThumb.storage_class.call(variant, uid)
  rescue => e
    ErrorTracking.notification_handler.call(e)
    # destroy the thumb if processing or storing fails
    @thumb&.destroy
  end
end