Module: Shrine::Plugins::Blurhash
- Defined in:
- lib/shrine/plugins/blurhash.rb
Defined Under Namespace
Modules: ClassMethods, FileMethods, InstanceMethods Classes: PixelsExtractor
Constant Summary collapse
- LOG_SUBSCRIBER =
lambda do |event| Shrine.logger.info "Blurhash (#{event.duration}ms) – #{{ io: event[:io].class, uploader: event[:uploader], }.inspect}" end
Class Method Summary collapse
Class Method Details
.configure(uploader, log_subscriber: LOG_SUBSCRIBER, **opts) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/shrine/plugins/blurhash.rb', line 15 def self.configure(uploader, log_subscriber: LOG_SUBSCRIBER, **opts) uploader.opts[:blurhash] ||= { extractor: :ruby_vips, on_error: :warn, auto_extraction: true, resize_to: 100, components: [4, 3], } uploader.opts[:blurhash].merge!(opts) # resolve error strategy uploader.opts[:blurhash][:on_error] = case uploader.opts[:blurhash][:on_error] when :fail then ->(error) { raise error } when :warn then ->(error) { Shrine.warn "Error occurred when attempting to extract blurhash: #{error.inspect}" } when :ignore then ->(error) {} else uploader.opts[:blurhash][:on_error] end uploader.subscribe(:blurhash, &log_subscriber) if uploader.respond_to?(:subscribe) end |