Module: Alchemy::StorageAdapter::Dragonfly::PictureClassMethods

Defined in:
app/models/alchemy/storage_adapter/dragonfly.rb

Class Method Summary collapse

Class Method Details

.included(base) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'app/models/alchemy/storage_adapter/dragonfly.rb', line 5

def self.included(base)
  base.class_eval do
    dragonfly_accessor :image_file, app: :alchemy_pictures do
      # Preprocess after uploading the picture
      after_assign do |image|
        if has_convertible_format?
          Alchemy.storage_adapter.preprocessor_class.new(image).call
        end
      end
    end

    has_many :thumbs, class_name: "Alchemy::PictureThumb", dependent: :destroy

    # Create important thumbnails upfront
    after_create -> { PictureThumb.generate_thumbs!(self) },
      if: :has_convertible_format?
  end
end