Module: Shrine::Plugins::DataUri::AttacherMethods

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

Instance Method Summary collapse

Instance Method Details

#assign_data_uri(uri, **options) ⇒ Object

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.


106
107
108
109
110
111
112
113
114
# 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_uriObject

Used by `<name>_data_uri` attachment method.


123
124
125
# File 'lib/shrine/plugins/data_uri.rb', line 123

def data_uri
  @data_uri
end

#data_uri=(uri) ⇒ Object

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


117
118
119
120
# File 'lib/shrine/plugins/data_uri.rb', line 117

def data_uri=(uri)
  assign_data_uri(uri)
  @data_uri = uri
end