Class: Lokii::MemoryServer
- Defined in:
- lib/lokii/servers/memory_server.rb
Overview
The memory server is a stub server that just allows you to fill an inbox and pull from an outbox. It is good as an example or as the basis of a mock server.
Instance Attribute Summary collapse
-
#inbox ⇒ Object
Local inbox and outbox per instance as queues.
-
#outbox ⇒ Object
Local inbox and outbox per instance as queues.
Attributes inherited from Server
Instance Method Summary collapse
- #check ⇒ Object
- #complete(message) ⇒ Object
-
#initialize ⇒ MemoryServer
constructor
A new instance of MemoryServer.
- #receive(text, number, sent) ⇒ Object
- #say(text, number, reply = nil) ⇒ Object
Methods inherited from Server
#connect, #daemon?, #disconnect, #process, #ready?, #running?, #setup, #stopped?
Constructor Details
#initialize ⇒ MemoryServer
Returns a new instance of MemoryServer.
11 12 13 14 |
# File 'lib/lokii/servers/memory_server.rb', line 11 def initialize self.inbox = [] self.outbox = [] end |
Instance Attribute Details
#inbox ⇒ Object
Local inbox and outbox per instance as queues
9 10 11 |
# File 'lib/lokii/servers/memory_server.rb', line 9 def inbox @inbox end |
#outbox ⇒ Object
Local inbox and outbox per instance as queues
9 10 11 |
# File 'lib/lokii/servers/memory_server.rb', line 9 def outbox @outbox end |
Instance Method Details
#check ⇒ Object
16 17 18 19 20 |
# File 'lib/lokii/servers/memory_server.rb', line 16 def check inbox.each {|| handle() } end |
#complete(message) ⇒ Object
22 23 24 |
# File 'lib/lokii/servers/memory_server.rb', line 22 def complete() inbox.delete() end |
#receive(text, number, sent) ⇒ Object
30 31 32 33 34 35 |
# File 'lib/lokii/servers/memory_server.rb', line 30 def receive(text, number, sent) inbox << {:text => text, :number => number, :created_at => sent, :processed_at => Time.now} end |
#say(text, number, reply = nil) ⇒ Object
26 27 28 |
# File 'lib/lokii/servers/memory_server.rb', line 26 def say(text, number, reply = nil) outbox << {:text => text, :number => number, :reply => reply} end |