Class: Bormashino::LocalStorage
- Inherits:
-
Object
- Object
- Bormashino::LocalStorage
- Includes:
- Singleton
- Defined in:
- lib/bormashino/local_storage.rb,
lib/bormashino/mock/local_storage.rb
Overview
LocalStorage mock for unit tests
Direct Known Subclasses
Instance Attribute Summary collapse
-
#store ⇒ Object
readonly
Returns the value of attribute store.
Instance Method Summary collapse
- #clear ⇒ Object
- #get_item(key_name) ⇒ Object
-
#initialize ⇒ LocalStorage
constructor
A new instance of LocalStorage.
- #key(index) ⇒ Object
- #length ⇒ Object
- #remove_item(key_name) ⇒ Object
- #set_item(key_name, key_value) ⇒ Object
Constructor Details
#initialize ⇒ LocalStorage
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
#store ⇒ Object (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
#clear ⇒ Object
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 |
#length ⇒ Object
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 |