Module: Fron::Storage::Store
- Included in:
- LocalStorage, SessionStorage
- Defined in:
- opal/fron/storage/store.rb
Overview
Abstract wrapper and adapter for the Storage API
Instance Method Summary collapse
-
#all ⇒ Array
Returns all values from the store.
-
#clear ⇒ Object
Clears the store, removeing all values.
-
#get(key) ⇒ Object
Gets a value from the store with the given key.
-
#keys ⇒ Array
Returns the all keys present in store.
-
#remove(key) ⇒ Object
Removes a value from the store with the given key.
-
#set(key, data) ⇒ Object
Sets a value to the store with the given key.
Instance Method Details
#all ⇒ Array
Returns all values from the store
44 45 46 |
# File 'opal/fron/storage/store.rb', line 44 def all keys.map { |key| get key } end |
#clear ⇒ Object
Clears the store, removeing all values
49 50 51 |
# File 'opal/fron/storage/store.rb', line 49 def clear `#{store}.clear()` end |
#get(key) ⇒ Object
Gets a value from the store with the given key
10 11 12 13 |
# File 'opal/fron/storage/store.rb', line 10 def get(key) value = `#{store}.getItem(#{key}) || false` value ? JSON.parse(value) : nil end |
#keys ⇒ Array
Returns the all keys present in store
33 34 35 36 37 38 39 |
# File 'opal/fron/storage/store.rb', line 33 def keys %x{ ret = [] for (var key in #{store}){ ret.push(key) } return ret } end |
#remove(key) ⇒ Object
Removes a value from the store with the given key
26 27 28 |
# File 'opal/fron/storage/store.rb', line 26 def remove(key) `#{store}.removeItem(#{key})` end |
#set(key, data) ⇒ Object
Sets a value to the store with the given key
19 20 21 |
# File 'opal/fron/storage/store.rb', line 19 def set(key, data) `#{store}.setItem(#{key},#{data.to_json})` end |