module Shrine::Plugins::DataUri::AttacherMethods

  1. lib/shrine/plugins/data_uri.rb

Methods

Public Instance

  1. data_uri
  2. data_uri=

Public Instance methods

data_uri ()

Form builders require the reader as well.

[show source]
# File lib/shrine/plugins/data_uri.rb, line 158
def data_uri
  @data_uri
end
data_uri= (uri)

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.

[show source]
# File lib/shrine/plugins/data_uri.rb, line 145
def data_uri=(uri)
  return if uri == ""

  data_file = shrine_class.data_uri(uri)
  assign(data_file)
rescue ParseError => error
  message = shrine_class.opts[:data_uri_error_message] || error.message
  message = message.call(uri) if message.respond_to?(:call)
  errors.replace [message]
  @data_uri = uri
end