module Shrine::Plugins::DataUri::AttacherMethods

Public Instance Methods

assign_data_uri(uri, **options) click to toggle source

Handles assignment of a data URI. If the regexp matches, it extracts the content type, decodes it, wrappes it in a StringIO and assigns it. If it fails, it sets the error message and assigns the uri in an instance variable so that it shows up on the UI.

# File lib/shrine/plugins/data_uri.rb, line 106
def assign_data_uri(uri, **options)
  return if uri == "" || uri.nil?

  data_file = shrine_class.data_uri(uri)
  attach_cached(data_file, **options)
rescue ParseError => error
  errors.clear << data_uri_error_messsage(uri, error)
  false
end
data_uri() click to toggle source

Used by ‘<name>_data_uri` attachment method.

# File lib/shrine/plugins/data_uri.rb, line 123
def data_uri
  @data_uri
end
data_uri=(uri) click to toggle source

Used by ‘<name>_data_uri=` attachment method.

# File lib/shrine/plugins/data_uri.rb, line 117
def data_uri=(uri)
  assign_data_uri(uri)
  @data_uri = uri
end

Private Instance Methods

data_uri_error_messsage(uri, error) click to toggle source

Generates an error message for failed data URI parse.

# File lib/shrine/plugins/data_uri.rb, line 130
def data_uri_error_messsage(uri, error)
  message = shrine_class.opts[:data_uri][:error_message]
  message = message.call(uri) if message.respond_to?(:call)
  message || error.message
end