Class: Malm::MessageDb

Inherits:
Object
  • Object
show all
Defined in:
lib/malm/message_db.rb

Instance Method Summary collapse

Constructor Details

#initializeMessageDb

Returns a new instance of MessageDb.



6
7
8
9
10
# File 'lib/malm/message_db.rb', line 6

def initialize
  @sempahore = Mutex.new

  @message_db = []
end

Instance Method Details

#create(message) ⇒ Object



12
13
14
15
16
17
18
# File 'lib/malm/message_db.rb', line 12

def create(message)
  @sempahore.synchronize do
    message[:id] = @message_db.size
    @message_db << message
    @message_db.size
  end
end

#find(id) ⇒ Object



26
27
28
29
30
# File 'lib/malm/message_db.rb', line 26

def find(id)
  @sempahore.synchronize do
    @message_db[id].dup
  end
end

#find_allObject



20
21
22
23
24
# File 'lib/malm/message_db.rb', line 20

def find_all
  @sempahore.synchronize do
    @message_db.dup
  end
end