Class: HashBack::Backend
- Inherits:
-
Object
- Object
- HashBack::Backend
- Defined in:
- lib/hashback/backend.rb
Overview
Proxy class over a key-value storage object which adds a namespace to keys. Useful if you have a number of different things that are saving to the same object space. Of course, then you may want to consider just opening up new key-value stores. This class may safely be ignored if not needed by your application.
Instance Method Summary collapse
- #[](key) ⇒ Object
- #[]=(key, value) ⇒ Object
- #delete(key) ⇒ Object
-
#initialize(namespace, backend) ⇒ Backend
constructor
Backend accepts a namespace which will be added to all keys on retrieval and setting, and a backend that responds to Hash-like methods.
Constructor Details
#initialize(namespace, backend) ⇒ Backend
Backend accepts a namespace which will be added to all keys on retrieval and setting, and a backend that responds to Hash-like methods. Moneta classes see the Moneta gem) work well as the backends to this class.
12 13 14 15 |
# File 'lib/hashback/backend.rb', line 12 def initialize(namespace, backend) @namespace = namespace @backend = backend end |
Instance Method Details
#[](key) ⇒ Object
17 18 19 |
# File 'lib/hashback/backend.rb', line 17 def [](key) @backend[key_name_for(key)] end |
#[]=(key, value) ⇒ Object
21 22 23 |
# File 'lib/hashback/backend.rb', line 21 def []=(key, value) @backend[key_name_for(key)] = value end |
#delete(key) ⇒ Object
25 26 27 |
# File 'lib/hashback/backend.rb', line 25 def delete(key) @backend.delete(key_name_for(key)) end |