Class: GovFakeNotify::AttachmentStore
- Inherits:
-
Object
- Object
- GovFakeNotify::AttachmentStore
- Includes:
- Singleton
- Defined in:
- lib/gov_fake_notify/attachment_store.rb
Overview
A central store for storing all state in the app - uses a basic PStore
Instance Method Summary collapse
-
#fetch(id) ⇒ Hash, Nil
Fetch a file from the store.
-
#store(file_data) ⇒ Hash
Given a hash containing the data that comes from the client side ‘prepare_upload’ method, this method stores the data in a file and returns the same hash but with the base64 data replaced with a file path where the data is stored.
Instance Method Details
#fetch(id) ⇒ Hash, Nil
Fetch a file from the store
35 36 37 38 |
# File 'lib/gov_fake_notify/attachment_store.rb', line 35 def fetch(id) file_path = File.join(, id.gsub(/[^a-zA-Z0-9\-]/, '')) File.exist?(file_path) ? { 'file' => file_path } : nil end |
#store(file_data) ⇒ Hash
Given a hash containing the data that comes from the client side ‘prepare_upload’ method,
this method stores the data in a file and returns the same hash but with the base64 data
replaced with a file path where the data is stored.
22 23 24 25 26 27 28 |
# File 'lib/gov_fake_notify/attachment_store.rb', line 22 def store(file_data) file_path = File.join(, SecureRandom.uuid) File.open(file_path, 'wb') do |file| file.write(Base64.decode64(file_data['file'])) end file_data.merge('file' => file_path) end |