Class: Tina4::Realtime::LocalStorage
- Inherits:
-
StorageBackend
- Object
- StorageBackend
- Tina4::Realtime::LocalStorage
- Defined in:
- lib/tina4/realtime/local_storage.rb
Overview
Zero-dependency filesystem store. The default backend.
Instance Method Summary collapse
- #delete(key) ⇒ Object
- #exists?(key) ⇒ Boolean
- #get(key) ⇒ Object
-
#initialize(directory = nil) ⇒ LocalStorage
constructor
A new instance of LocalStorage.
- #put(key, data, _mime = "application/octet-stream") ⇒ Object
-
#url(_key, _ttl = 3600) ⇒ Object
No direct URL: the permissioned app download route serves local files.
Constructor Details
#initialize(directory = nil) ⇒ LocalStorage
Returns a new instance of LocalStorage.
9 10 11 12 13 |
# File 'lib/tina4/realtime/local_storage.rb', line 9 def initialize(directory = nil) super() @directory = File.(directory || ENV["TINA4_STORAGE_DIR"] || "data/rt_storage") FileUtils.mkdir_p(@directory) end |
Instance Method Details
#delete(key) ⇒ Object
31 32 33 34 35 36 |
# File 'lib/tina4/realtime/local_storage.rb', line 31 def delete(key) File.delete(path_for(key)) nil rescue Errno::ENOENT, ArgumentError nil end |
#exists?(key) ⇒ Boolean
38 39 40 41 42 |
# File 'lib/tina4/realtime/local_storage.rb', line 38 def exists?(key) File.file?(path_for(key)) rescue ArgumentError false end |
#get(key) ⇒ Object
20 21 22 23 24 |
# File 'lib/tina4/realtime/local_storage.rb', line 20 def get(key) File.binread(path_for(key)) rescue Errno::ENOENT, ArgumentError nil end |
#put(key, data, _mime = "application/octet-stream") ⇒ Object
15 16 17 18 |
# File 'lib/tina4/realtime/local_storage.rb', line 15 def put(key, data, _mime = "application/octet-stream") File.binwrite(path_for(key), data) nil end |
#url(_key, _ttl = 3600) ⇒ Object
No direct URL: the permissioned app download route serves local files.
27 28 29 |
# File 'lib/tina4/realtime/local_storage.rb', line 27 def url(_key, _ttl = 3600) nil end |