Class: Shrine::Plugins::KitheDerivativeDefinitions
- Inherits:
-
Object
- Object
- Shrine::Plugins::KitheDerivativeDefinitions
- Defined in:
- lib/shrine/plugins/kithe_derivative_definitions.rb
Defined Under Namespace
Modules: AttacherClassMethods, AttacherMethods
Class Method Summary collapse
Class Method Details
.configure(uploader, *opts) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/shrine/plugins/kithe_derivative_definitions.rb', line 4 def self.configure(uploader, *opts) # use Rails class_attribute to conveniently have a class-level place # to store our derivative definitions that are inheritable and overrideable. # We store it on the Attacher class, because that's where shrine # puts derivative processor definitions, so seems appropriate. Normally # not touched directly by non-kithe code. uploader::Attacher.class_attribute :kithe_derivative_definitions, instance_writer: false, default: [] # Kithe exersizes lifecycle control over derivatives, normally just the # shrine processor labelled :kithe_derivatives. But you can opt additional shrine # derivative processors into kithe control by listing their labels in this attribute. # # @example # # class AssetUploader < Kithe::AssetUploader # Attacher.kithe_include_derivatives_processors += [:my_processor] # Attacher.derivatives(:my_processor) do |original| # derivatives # end # end # uploader::Attacher.class_attribute :kithe_include_derivatives_processors, instance_writer: false, default: [] # Register our derivative processor, that will create our registered derivatives, # with our custom options. # # We do download: false, so when our `lazy` argument is in use, original does not get eagerly downloaded, # but only gets downloaded if needed to make derivatives. This is great for performance, especially # when running batch job to add just missing derivatives. uploader::Attacher.derivatives(:kithe_derivatives, download: false) do |original, **| Kithe::Asset::DerivativeCreator.new(self.class.kithe_derivative_definitions, source_io: original, shrine_attacher: self, only: [:only], except: [:except], lazy: [:lazy] ).call end end |