module Shrine::Plugins::Derivatives::AttacherClassMethods

Public Instance Methods

derivatives(name = :default, download: true, &block)
derivatives_processor(name = :default, download: true, &block) click to toggle source

Registers a derivatives processor on the attacher class.

Attacher.derivatives_processor :thumbnails do |original|
  # ...
end

By default, Shrine will convert the source IO object into a file before it’s passed to the processor block. You can set ‘download: false` to pass the source IO object to the processor block as is.

Attacher.derivatives_processor :thumbnails, download: false do |original|
  # ...
end

This can be useful if you’d like to defer or avoid a possibly expensive download operation for processor logic that does not require it.

# File lib/shrine/plugins/derivatives.rb, line 65
def derivatives_processor(name = :default, download: true, &block)
  if block
    shrine_class.derivatives_options[:processors][name.to_sym] = block
    shrine_class.derivatives_options[:processor_settings][name.to_sym] = { download: download }
  else
    shrine_class.derivatives_options[:processors].fetch(name.to_sym) do
      fail Error, "derivatives processor #{name.inspect} not registered" unless name == :default
    end
  end
end
Also aliased as: derivatives
derivatives_processor_settings(name) click to toggle source

Returns settings for the given derivatives processor.

Attacher.derivatives_processor_settings(:thumbnails) #=> { download: true }
# File lib/shrine/plugins/derivatives.rb, line 80
def derivatives_processor_settings(name)
  shrine_class.derivatives_options[:processor_settings][name.to_sym] || {}
end
derivatives_storage(storage_key = nil, &block) click to toggle source

Specifies default storage to which derivatives will be uploaded.

Attacher.derivatives_storage :other_store
# or
Attacher.derivatives_storage do |name|
  if name == :thumbnail
    :thumbnail_store
  else
    :store
  end
end
# File lib/shrine/plugins/derivatives.rb, line 95
def derivatives_storage(storage_key = nil, &block)
  if storage_key || block
    shrine_class.derivatives_options[:storage] = storage_key || block
  else
    shrine_class.derivatives_options[:storage]
  end
end