Class: Shrine::Plugins::KitheDerivativeDefinitions

Inherits:
Object
  • Object
show all
Defined in:
lib/shrine/plugins/kithe_derivative_definitions.rb

Defined Under Namespace

Modules: AttacherClassMethods

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
# 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.
  uploader::Attacher.class_attribute :kithe_derivative_definitions, instance_writer: false, default: []

  # Register our derivative processor, that will create our registered derivatives,
  # with our custom options.
  uploader::Attacher.derivatives(:kithe_derivatives) do |original, **options|
    Kithe::Asset::DerivativeCreator.new(self.class.kithe_derivative_definitions,
      source_io: original,
      shrine_attacher: self,
      only: options[:only],
      except: options[:except],
      lazy: options[:lazy]
    ).call
  end
end