Class: Trunk::Storage
- Inherits:
-
Object
- Object
- Trunk::Storage
- Defined in:
- lib/trunk/storage.rb
Instance Attribute Summary collapse
-
#hash ⇒ Object
readonly
Returns the value of attribute hash.
Instance Method Summary collapse
- #fetch(key) ⇒ Object
-
#initialize(hash, serializer) ⇒ Storage
constructor
A new instance of Storage.
- #store(key, value) ⇒ Object
Constructor Details
#initialize(hash, serializer) ⇒ Storage
Returns a new instance of Storage.
5 6 7 8 |
# File 'lib/trunk/storage.rb', line 5 def initialize(hash, serializer) @hash = hash @serializer = serializer end |
Instance Attribute Details
#hash ⇒ Object (readonly)
Returns the value of attribute hash.
3 4 5 |
# File 'lib/trunk/storage.rb', line 3 def hash @hash end |
Instance Method Details
#fetch(key) ⇒ Object
10 11 12 13 14 |
# File 'lib/trunk/storage.rb', line 10 def fetch(key) value = @hash[key] return if value.nil? @serializer.deserialize(value) end |
#store(key, value) ⇒ Object
16 17 18 |
# File 'lib/trunk/storage.rb', line 16 def store(key, value) @hash[key] = @serializer.serialize(value) end |