Module: EchoUploads::Model
- Defined in:
- lib/echo_uploads/model.rb
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
Instance Method Summary collapse
- #echo_uploads_data ⇒ Object
-
#echo_uploads_data=(data) ⇒ Object
Pass in a hash that’s been encoded as JSON and then Base64.
-
#map_metadata(attr) ⇒ Object
Helper method used internally Echo Uploads.
Class Method Details
.included(base) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/echo_uploads/model.rb', line 7 def self.included(base) base.class_eval do class_attribute :echo_uploads_config include ::EchoUploads::Validation include ::EchoUploads::PermFileSaving include ::EchoUploads::TempFileSaving extend ClassMethods end end |
Instance Method Details
#echo_uploads_data ⇒ Object
19 20 21 22 23 24 25 26 27 |
# File 'lib/echo_uploads/model.rb', line 19 def echo_uploads_data Base64.encode64(JSON.dump(self.class.echo_uploads_config.inject({}) do |hash, (attr, cfg)| = send("#{attr}_tmp_metadata") if hash[attr] = {'id' => .id, 'key' => .key} end hash end)).strip end |
#echo_uploads_data=(data) ⇒ Object
Pass in a hash that’s been encoded as JSON and then Base64.
30 31 32 33 34 35 36 37 38 |
# File 'lib/echo_uploads/model.rb', line 30 def echo_uploads_data=(data) parsed = JSON.parse Base64.decode64(data) parsed.each do |attr, attr_data| # Must verify that the metadata record is temporary. If not, an attacker could # pass the ID of a permanent record and change its owner. = ::EchoUploads::File.where(key: attr_data['key'], temporary: true).find(attr_data['id']) send("#{attr}_tmp_metadata=", ) end end |
#map_metadata(attr) ⇒ Object
Helper method used internally Echo Uploads.
41 42 43 44 |
# File 'lib/echo_uploads/model.rb', line 41 def (attr) = send("#{attr}_metadata") ? yield() : nil end |