class Switches::Backends::Memory
Public Class Methods
bus()
click to toggle source
# File lib/switches/backends/memory.rb, line 6 def self.bus @bus ||= Bus.new end
clear()
click to toggle source
# File lib/switches/backends/memory.rb, line 14 def self.clear bus.clear storage.clear end
new(uri, instance)
click to toggle source
# File lib/switches/backends/memory.rb, line 19 def initialize(uri, instance) @instance = instance end
storage()
click to toggle source
# File lib/switches/backends/memory.rb, line 10 def self.storage @storage ||= {} end
Public Instance Methods
clear()
click to toggle source
# File lib/switches/backends/memory.rb, line 44 def clear self.class.clear end
get(item)
click to toggle source
# File lib/switches/backends/memory.rb, line 27 def get(item) if json = self.class.storage[item.key] JSONSerializer.deserialize(json) end end
listen()
click to toggle source
# File lib/switches/backends/memory.rb, line 33 def listen self.class.bus.subscribe do |message| update = Update.load(message) @instance.notified(update) end end
notify(update)
click to toggle source
# File lib/switches/backends/memory.rb, line 40 def notify(update) self.class.bus.publish(update.to_json) end
set(item)
click to toggle source
# File lib/switches/backends/memory.rb, line 23 def set(item) self.class.storage[item.key] = item.to_json end
stop()
click to toggle source
# File lib/switches/backends/memory.rb, line 48 def stop end