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
end

#find_all_messages_by_from_id(id) ⇒ Object



27
28
29
# File 'lib/chatbox/memory_store.rb', line 27

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

#find_all_messages_by_to_id(id) ⇒ Object



23
24
25
# File 'lib/chatbox/memory_store.rb', line 23

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

#find_message(id) ⇒ Object



17
18
19
20
21
# File 'lib/chatbox/memory_store.rb', line 17

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

#mark_message_read!(id) ⇒ Object



7
8
9
# File 'lib/chatbox/memory_store.rb', line 7

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

#mark_message_unread!(id) ⇒ Object



11
12
13
# File 'lib/chatbox/memory_store.rb', line 11

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