Module: Shrine::Plugins::Derivatives::AttacherClassMethods
- Defined in:
- lib/shrine/plugins/derivatives.rb
Instance Method Summary collapse
-
#derivatives_processor(name = :default, download: true, &block) ⇒ Object
(also: #derivatives)
Registers a derivatives processor on the attacher class.
-
#derivatives_processor_settings(name) ⇒ Object
Returns settings for the given derivatives processor.
-
#derivatives_storage(storage_key = nil, &block) ⇒ Object
Specifies default storage to which derivatives will be uploaded.
Instance Method Details
#derivatives_processor(name = :default, download: true, &block) ⇒ Object Also known as: derivatives
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.
65 66 67 68 69 70 71 72 73 74 |
# File 'lib/shrine/plugins/derivatives.rb', line 65 def derivatives_processor(name = :default, download: true, &block) if block shrine_class.[:processors][name.to_sym] = block shrine_class.[:processor_settings][name.to_sym] = { download: download } else shrine_class.[:processors].fetch(name.to_sym) do fail Error, "derivatives processor #{name.inspect} not registered" unless name == :default end end end |
#derivatives_processor_settings(name) ⇒ Object
Returns settings for the given derivatives processor.
Attacher.derivatives_processor_settings(:thumbnails) #=> { download: true }
80 81 82 |
# File 'lib/shrine/plugins/derivatives.rb', line 80 def derivatives_processor_settings(name) shrine_class.[:processor_settings][name.to_sym] || {} end |
#derivatives_storage(storage_key = nil, &block) ⇒ Object
95 96 97 98 99 100 101 |
# File 'lib/shrine/plugins/derivatives.rb', line 95 def derivatives_storage(storage_key = nil, &block) if storage_key || block shrine_class.[:storage] = storage_key || block else shrine_class.[:storage] end end |