Class: SpeedGun::Store
- Inherits:
-
Object
show all
- Defined in:
- lib/speed_gun/store.rb
Defined Under Namespace
Classes: FileStore, MemoryStore
Instance Method Summary
collapse
Instance Method Details
#deserialize(key, msg) ⇒ Object
9
10
11
12
13
14
15
16
|
# File 'lib/speed_gun/store.rb', line 9
def deserialize(key, msg)
return nil if msg.nil? || msg.empty?
hash = MessagePack.unpack(msg)
klass, id = *key.split('/', 2)
obj = Object.const_get(klass).from_hash(hash)
obj.instance_variable_set(:@id, id)
obj
end
|
#serialize(obj) ⇒ Object
5
6
7
|
# File 'lib/speed_gun/store.rb', line 5
def serialize(obj)
["#{obj.class.name}/#{obj.id}", MessagePack.pack(obj.to_hash)]
end
|