Class: KVMultiplex::Providers::Memory
- Inherits:
-
KVMultiplex::Provider
- Object
- KVMultiplex::Provider
- KVMultiplex::Providers::Memory
- Defined in:
- lib/kvmultiplex/providers/memory.rb
Overview
The ‘Memory` provider just stores a list of potential values. Since other providers are sparse trees (there’s no “list” operation), we’re just going to store values as complete subkeys, stringified internally to avoid accidentally changing a subkey further down the line.
Instance Method Summary collapse
- #get(subkey, _full_key) ⇒ Object
-
#initialize ⇒ Memory
constructor
A new instance of Memory.
- #set(subkey, _full_key, value) ⇒ Object
Constructor Details
#initialize ⇒ Memory
Returns a new instance of Memory.
13 14 15 |
# File 'lib/kvmultiplex/providers/memory.rb', line 13 def initialize @contents = {} end |
Instance Method Details
#get(subkey, _full_key) ⇒ Object
17 18 19 20 |
# File 'lib/kvmultiplex/providers/memory.rb', line 17 def get(subkey, _full_key) v = @contents[get_content_key(subkey)] v.nil? ? v : MultiJson.load(v) end |
#set(subkey, _full_key, value) ⇒ Object
22 23 24 25 26 |
# File 'lib/kvmultiplex/providers/memory.rb', line 22 def set(subkey, _full_key, value) # do NOT use JSON.generate here; it's unsafe in environments that pull json 1.8.6 @contents[get_content_key(subkey)] = value.nil? ? nil : MultiJson.dump(value) value end |