Module: Shrine::Plugins::DataUri

Defined in:
lib/shrine/plugins/data_uri.rb

Overview

Documentation can be found on shrinerb.com/docs/plugins/data_uri

Defined Under Namespace

Modules: AttacherMethods, AttachmentMethods, ClassMethods, FileMethods Classes: ParseError

Constant Summary collapse

DATA_REGEXP =
/data:/
MEDIA_TYPE_REGEXP =
/[-\w.+]+\/[-\w.+]+(;[-\w.+]+=[^;,]+)*/
BASE64_REGEXP =
/;base64/
CONTENT_SEPARATOR =
/,/
DEFAULT_CONTENT_TYPE =
"text/plain"
LOG_SUBSCRIBER =
-> (event) do
  Shrine.logger.info "Data URI (#{event.duration}ms) – #{{
    uploader: event[:uploader],
  }.inspect}"
end

Class Method Summary collapse

Class Method Details

.configure(uploader, log_subscriber: LOG_SUBSCRIBER, **opts) ⇒ Object


31
32
33
34
35
36
37
# File 'lib/shrine/plugins/data_uri.rb', line 31

def self.configure(uploader, log_subscriber: LOG_SUBSCRIBER, **opts)
  uploader.opts[:data_uri] ||= {}
  uploader.opts[:data_uri].merge!(opts)

  # instrumentation plugin integration
  uploader.subscribe(:data_uri, &log_subscriber) if uploader.respond_to?(:subscribe)
end

.load_dependencies(uploader) ⇒ Object


27
28
29
# File 'lib/shrine/plugins/data_uri.rb', line 27

def self.load_dependencies(uploader, *)
  uploader.plugin :validation
end