Class: Alchemy::StorageAdapter::ActiveStorage::Preprocessor

Inherits:
Object
  • Object
show all
Defined in:
app/models/alchemy/storage_adapter/active_storage/preprocessor.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attachable) ⇒ Preprocessor

Returns a new instance of Preprocessor.



6
7
8
# File 'app/models/alchemy/storage_adapter/active_storage/preprocessor.rb', line 6

def initialize(attachable)
  @attachable = attachable
end

Instance Attribute Details

#attachableObject (readonly)

Returns the value of attribute attachable.



23
24
25
# File 'app/models/alchemy/storage_adapter/active_storage/preprocessor.rb', line 23

def attachable
  @attachable
end

Class Method Details

.generate_thumbs!(attachable) ⇒ Object



26
27
28
29
30
# File 'app/models/alchemy/storage_adapter/active_storage/preprocessor.rb', line 26

def generate_thumbs!(attachable)
  Alchemy::Picture::THUMBNAIL_SIZES.values.each do |size|
    process_thumb(attachable, size: size, flatten: true)
  end
end

.process_thumb(attachable, options = {}) ⇒ Object



32
33
34
35
36
# File 'app/models/alchemy/storage_adapter/active_storage/preprocessor.rb', line 32

def process_thumb(attachable, options = {})
  attachable.variant :thumb,
    **Alchemy::DragonflyToImageProcessing.call(options),
    preprocessed: true
end

Instance Method Details

#callObject

Preprocess images after upload

Define preprocessing options in the Alchemy.config

preprocess_image_resize [String] - Downsizing example: '1000x1000>'


16
17
18
19
20
21
# File 'app/models/alchemy/storage_adapter/active_storage/preprocessor.rb', line 16

def call
  max_image_size = Alchemy.config.get(:preprocess_image_resize)
  if max_image_size.present?
    self.class.process_thumb(attachable, size: max_image_size)
  end
end