Module: Fron::Storage::LocalStorage

Defined in:
opal/fron/storage/local_storage.rb

Overview

Local Storage wrapper and adapter

Class Method Summary collapse

Class Method Details

.allArray

Returns all values from local storage


44
45
46
# File 'opal/fron/storage/local_storage.rb', line 44

def self.all
  keys.map { |key| get key }
end

.clearObject

Clears local storage removeing all values


49
50
51
# File 'opal/fron/storage/local_storage.rb', line 49

def self.clear
  `window.localStorage.clear()`
end

.get(key) ⇒ Object

Gets a value from local storage with the given key


10
11
12
13
# File 'opal/fron/storage/local_storage.rb', line 10

def self.get(key)
  value = `window.localStorage.getItem(#{key}) || false`
  value ? JSON.parse(value) : nil
end

.keysArray

Returns the all keys present in local storage


33
34
35
36
37
38
39
# File 'opal/fron/storage/local_storage.rb', line 33

def self.keys
  %x{
    ret = []
    for (var key in localStorage){ ret.push(key) }
    return ret
  }
end

.remove(key) ⇒ Object

Removes a value from local storage with the given key


26
27
28
# File 'opal/fron/storage/local_storage.rb', line 26

def self.remove(key)
  `window.localStorage.removeItem(#{key})`
end

.set(key, data) ⇒ Object

Sets a value to local storage with the given key


19
20
21
# File 'opal/fron/storage/local_storage.rb', line 19

def self.set(key, data)
  `window.localStorage.setItem(#{key},#{data.to_json})`
end