Class: Swarm::Storage::KeyValueStorage
- Inherits:
-
Object
- Object
- Swarm::Storage::KeyValueStorage
show all
- Defined in:
- lib/swarm/storage/key_value_storage.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
Returns a new instance of KeyValueStorage.
6
7
8
|
# File 'lib/swarm/storage/key_value_storage.rb', line 6
def initialize(store)
@store = store
end
|
Instance Attribute Details
#store ⇒ Object
Returns the value of attribute store.
4
5
6
|
# File 'lib/swarm/storage/key_value_storage.rb', line 4
def store
@store
end
|
Instance Method Details
#[](key) ⇒ Object
28
29
30
|
# File 'lib/swarm/storage/key_value_storage.rb', line 28
def [](key)
deserialize(store[key])
end
|
#[]=(key, value) ⇒ Object
32
33
34
|
# File 'lib/swarm/storage/key_value_storage.rb', line 32
def []=(key, value)
store[key] = serialize(value)
end
|
#delete(key) ⇒ Object
36
37
38
|
# File 'lib/swarm/storage/key_value_storage.rb', line 36
def delete(key)
raise "Not implemented yet!"
end
|
#deserialize(value) ⇒ Object
23
24
25
26
|
# File 'lib/swarm/storage/key_value_storage.rb', line 23
def deserialize(value)
return nil if value.nil?
JSON.parse(value)
end
|
#ids_for_type(type) ⇒ Object
14
15
16
|
# File 'lib/swarm/storage/key_value_storage.rb', line 14
def ids_for_type(type)
raise "Not implemented yet!"
end
|
#regex_for_type(type) ⇒ Object
10
11
12
|
# File 'lib/swarm/storage/key_value_storage.rb', line 10
def regex_for_type(type)
/^#{type}\:(.*)/
end
|
#serialize(value) ⇒ Object
18
19
20
21
|
# File 'lib/swarm/storage/key_value_storage.rb', line 18
def serialize(value)
return nil if value.nil?
value.to_json
end
|
#truncate ⇒ Object
40
41
42
|
# File 'lib/swarm/storage/key_value_storage.rb', line 40
def truncate
raise "Not implemented yet!"
end
|