Class: Alchemy::PictureThumb

Inherits:
BaseRecord
  • Object
show all
Defined in:
app/models/alchemy/picture_thumb.rb,
app/models/alchemy/picture_thumb/uid.rb,
app/models/alchemy/picture_thumb/create.rb,
app/models/alchemy/picture_thumb/signature.rb,
app/models/alchemy/picture_thumb/file_store.rb

Overview

The persisted version of a rendered picture variant

You can configure the generator class to implement a different thumbnail store (ie. a remote file storage).

config/initializers/alchemy.rb
Alchemy::PictureThumb.storage_class = My::ThumbnailStore

Defined Under Namespace

Classes: Create, FileStore, Signature, Uid

Constant Summary

Constants included from SearchableResource

SearchableResource::SEARCHABLE_COLUMN_TYPES

Class Method Summary collapse

Methods included from SearchableResource

#ransackable_associations, #ransackable_attributes, #ransortable_attributes

Class Method Details

.generate_thumbs!(picture) ⇒ Object

Upfront generation of picture thumbnails

Called after a Alchemy::Picture has been created (after an image has been uploaded)

Generates three types of thumbnails that are used by Alchemys picture archive and persists them in the configures file store (Default Dragonfly::FileDataStore).



41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'app/models/alchemy/picture_thumb.rb', line 41

def generate_thumbs!(picture)
  Alchemy::Picture::THUMBNAIL_SIZES.values.each do |size|
    variant = Alchemy::PictureVariant.new(picture, {
      size: size,
      flatten: true
    })
    signature = Alchemy::PictureThumb::Signature.call(variant)
    thumb = find_by(signature: signature)
    next if thumb

    uid = Alchemy::PictureThumb::Uid.call(signature, variant)
    Alchemy::PictureThumb::Create.call(variant, signature, uid)
  end
end

.storage_classObject

Thumbnail storage class

See Also:



22
23
24
# File 'app/models/alchemy/picture_thumb.rb', line 22

def storage_class
  @_storage_class ||= Alchemy::PictureThumb::FileStore
end

.storage_class=(klass) ⇒ Object

Set a thumbnail storage class

See Also:



29
30
31
# File 'app/models/alchemy/picture_thumb.rb', line 29

def storage_class=(klass)
  @_storage_class = klass
end