class KVMultiplex::Providers::Memory
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.
Public Class Methods
new()
click to toggle source
# File lib/kvmultiplex/providers/memory.rb, line 13 def initialize @contents = {} end
Public Instance Methods
get(subkey, _full_key)
click to toggle source
# 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)
click to toggle source
# 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
Private Instance Methods
get_content_key(subkey)
click to toggle source
# File lib/kvmultiplex/providers/memory.rb, line 30 def get_content_key(subkey) # Was originally a SHA1 hash, but I think that might be overkill. subkey.join('.') end