class LocalStore

Public Class Methods

[](key, *args, &block)
Alias for: method_missing
[]=(key, *args, &block)
Alias for: method_missing
clear() click to toggle source
# File lib/local_store.rb, line 35
def clear
  `Opal.global.localStorage.clear()`
  notify_subscribers
  nil
end
delete(key) click to toggle source
# File lib/local_store.rb, line 29
def delete(key)
  `Opal.global.localStorage.removeItem(key)`
  notify_subscribers
  nil
end
get(key, *args, &block)
Alias for: method_missing
method_missing(key, *args, &block) click to toggle source
# File lib/local_store.rb, line 5
def method_missing(key, *args, &block)
  if Isomorfeus.on_browser?
    if `args.length > 0`
      key = `key.endsWith('=')` ? key.chop : key
      value = args[0]
      `Opal.global.localStorage.setItem(key, value)`
      notify_subscribers
      value
    else
      # check store for value
      value = `Opal.global.localStorage.getItem(key)`
      return value if value
    end
  end
  # otherwise return nil
  return nil
end
Also aliased as: [], []=, get, set
set(key, *args, &block)
Alias for: method_missing