Class: Switches::Backends::Memory
- Inherits:
-
Object
- Object
- Switches::Backends::Memory
- Defined in:
- lib/switches/backends/memory.rb,
lib/switches/backends/memory/bus.rb
Defined Under Namespace
Classes: Bus
Class Method Summary collapse
Instance Method Summary collapse
- #clear ⇒ Object
- #get(item) ⇒ Object
-
#initialize(uri, instance) ⇒ Memory
constructor
A new instance of Memory.
- #listen ⇒ Object
- #notify(update) ⇒ Object
- #set(item) ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize(uri, instance) ⇒ Memory
Returns a new instance of Memory.
19 20 21 |
# File 'lib/switches/backends/memory.rb', line 19 def initialize(uri, instance) @instance = instance end |
Class Method Details
.bus ⇒ Object
6 7 8 |
# File 'lib/switches/backends/memory.rb', line 6 def self.bus @bus ||= Bus.new end |
.clear ⇒ Object
14 15 16 17 |
# File 'lib/switches/backends/memory.rb', line 14 def self.clear bus.clear storage.clear end |
.storage ⇒ Object
10 11 12 |
# File 'lib/switches/backends/memory.rb', line 10 def self.storage @storage ||= {} end |
Instance Method Details
#clear ⇒ Object
44 45 46 |
# File 'lib/switches/backends/memory.rb', line 44 def clear self.class.clear end |
#get(item) ⇒ Object
27 28 29 30 31 |
# File 'lib/switches/backends/memory.rb', line 27 def get(item) if json = self.class.storage[item.key] JSONSerializer.deserialize(json) end end |
#listen ⇒ Object
33 34 35 36 37 38 |
# File 'lib/switches/backends/memory.rb', line 33 def listen self.class.bus.subscribe do || update = Update.load() @instance.notified(update) end end |
#notify(update) ⇒ Object
40 41 42 |
# File 'lib/switches/backends/memory.rb', line 40 def notify(update) self.class.bus.publish(update.to_json) end |
#set(item) ⇒ Object
23 24 25 |
# File 'lib/switches/backends/memory.rb', line 23 def set(item) self.class.storage[item.key] = item.to_json end |
#stop ⇒ Object
48 49 |
# File 'lib/switches/backends/memory.rb', line 48 def stop end |