Class: Chatbox::MemoryStore

Inherits:
Object
  • Object
show all
Defined in:
lib/chatbox/memory_store.rb

Defined Under Namespace

Classes: Record

Instance Method Summary collapse

Instance Method Details

#add_message(attrs) ⇒ Object



3
4
5
# File 'lib/chatbox/memory_store.rb', line 3

def add_message(attrs)
  attrs_list << attrs.merge('read' => false)
end

#find_message(id) ⇒ Object



19
20
21
22
23
# File 'lib/chatbox/memory_store.rb', line 19

def find_message(id)
  if attrs = attrs_list.detect { |attrs| attrs['id'] == id }
    Record.new attrs
  end
end

#find_messages_by_from_id(id) ⇒ Object



29
30
31
# File 'lib/chatbox/memory_store.rb', line 29

def find_messages_by_from_id(id)
  attrs_list.select { |attrs| attrs['from_id'] == id }.map { |attrs| Record.new attrs }
end

#find_messages_by_to_id(id) ⇒ Object



25
26
27
# File 'lib/chatbox/memory_store.rb', line 25

def find_messages_by_to_id(id)
  attrs_list.select { |attrs| attrs['to_id'] == id }.map { |attrs| Record.new attrs }
end

#mark_message_read!(id) ⇒ Object



9
10
11
# File 'lib/chatbox/memory_store.rb', line 9

def mark_message_read!(id)
  attrs_list.detect { |attrs| attrs['id'] == id }.merge! 'read' => true
end

#mark_message_unread!(id) ⇒ Object



13
14
15
# File 'lib/chatbox/memory_store.rb', line 13

def mark_message_unread!(id)
  attrs_list.detect { |attrs| attrs['id'] == id }.merge! 'read' => false
end