Skip to content

Commit

Permalink
Make image preprocessor configurable
Browse files Browse the repository at this point in the history
You can define your own preprocessor class

    # config/initializers/alchemy.rb
    Alchemy::Picture.preprocessor_class = My::ImagePreprocessor
  • Loading branch information
tvdeyen committed Jun 15, 2020
1 parent e251ae5 commit a7479da
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion app/models/alchemy/picture.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,25 @@ class Picture < BaseRecord
raise PictureInUseError, Alchemy.t(:cannot_delete_picture_notice) % { name: name }
end

# Image preprocessing class
def self.preprocessor_class
@_preprocessor_class ||= Preprocessor
end

# Set a image preprocessing class
#
# # config/initializers/alchemy.rb
# Alchemy::Picture.preprocessor_class = My::ImagePreprocessor
#
def self.preprocessor_class=(klass)
@_preprocessor_class = klass
end

# Enables Dragonfly image processing
dragonfly_accessor :image_file, app: :alchemy_pictures do
# Preprocess after uploading the picture
after_assign do |image|
Preprocessor.new(image).call
self.class.preprocessor_class.new(image).call
end
end

Expand Down

0 comments on commit a7479da

Please sign in to comment.