Class: Bormashino::LocalStorage

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/bormashino/local_storage.rb,
lib/bormashino/mock/local_storage.rb

Overview

LocalStorage mock for unit tests

Direct Known Subclasses

SessionStorage

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeLocalStorage

Returns a new instance of LocalStorage.



11
12
13
# File 'lib/bormashino/local_storage.rb', line 11

def initialize
  @storage = JS.global[:localStorage]
end

Instance Attribute Details

#storeObject (readonly)

Returns the value of attribute store.



7
8
9
# File 'lib/bormashino/mock/local_storage.rb', line 7

def store
  @store
end

Instance Method Details

#clearObject



35
36
37
# File 'lib/bormashino/local_storage.rb', line 35

def clear
  @storage.call(:clear)
end

#get_item(key_name) ⇒ Object



23
24
25
# File 'lib/bormashino/local_storage.rb', line 23

def get_item(key_name)
  @storage.call(:getItem, key_name).to_rb
end

#key(index) ⇒ Object



19
20
21
# File 'lib/bormashino/local_storage.rb', line 19

def key(index)
  @storage.call(:key, index).to_rb
end

#lengthObject



15
16
17
# File 'lib/bormashino/local_storage.rb', line 15

def length
  @storage[:length].to_rb
end

#remove_item(key_name) ⇒ Object



31
32
33
# File 'lib/bormashino/local_storage.rb', line 31

def remove_item(key_name)
  @storage.call(:removeItem, key_name)
end

#set_item(key_name, key_value) ⇒ Object



27
28
29
# File 'lib/bormashino/local_storage.rb', line 27

def set_item(key_name, key_value)
  @storage.call(:setItem, key_name, key_value)
end