Class: Lokii::MemoryServer

Inherits:
Server
  • Object
show all
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

Attributes inherited from Server

#handlers, #ready, #stopped

Instance Method Summary collapse

Methods inherited from Server

#connect, #daemon?, #disconnect, #process, #ready?, #running?, #setup, #stopped?

Constructor Details

#initializeMemoryServer

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

#inboxObject

Local inbox and outbox per instance as queues



9
10
11
# File 'lib/lokii/servers/memory_server.rb', line 9

def inbox
  @inbox
end

#outboxObject

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

#checkObject



16
17
18
19
20
# File 'lib/lokii/servers/memory_server.rb', line 16

def check
  inbox.each {|message|
    handle(message)    
  }      
end

#complete(message) ⇒ Object



22
23
24
# File 'lib/lokii/servers/memory_server.rb', line 22

def complete(message)
  inbox.delete(message)
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