module Shrine::Plugins::Derivatives::AttacherClassMethods

  1. lib/shrine/plugins/derivatives.rb

Public Instance Aliases

derivatives -> derivatives_processor

Public Instance methods

derivatives_processor(name = :default, download: true, &block)

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.

[show source]
   # File lib/shrine/plugins/derivatives.rb
65 def derivatives_processor(name = :default, download: true, &block)
66   if block
67     shrine_class.derivatives_options[:processors][name.to_sym] = block
68     shrine_class.derivatives_options[:processor_settings][name.to_sym] = { download: download }
69   else
70     shrine_class.derivatives_options[:processors].fetch(name.to_sym) do
71       fail Error, "derivatives processor #{name.inspect} not registered" unless name == :default
72     end
73   end
74 end
derivatives_processor_settings(name)

Returns settings for the given derivatives processor.

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

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
[show source]
    # File lib/shrine/plugins/derivatives.rb
 95 def derivatives_storage(storage_key = nil, &block)
 96   if storage_key || block
 97     shrine_class.derivatives_options[:storage] = storage_key || block
 98   else
 99     shrine_class.derivatives_options[:storage]
100   end
101 end