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

Instance Method Details

#allArray

Returns all values from the store

Returns:

  • (Array)

    Array of values



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

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

#clearObject

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

Parameters:

Returns:



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

#keysArray

Returns the all keys present in store

Returns:

  • (Array)

    Array of keys



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

Parameters:



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

Parameters:



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

def set(key, data)
  `#{store}.setItem(#{key},#{data.to_json})`
end