class Chatbox::MemoryStore
Attributes
id_generator[R]
Public Class Methods
new(id_generator: -> { SecureRandom.uuid }
click to toggle source
# File lib/chatbox/memory_store.rb, line 5 def initialize(id_generator: -> { SecureRandom.uuid }) @id_generator = id_generator end
Public Instance Methods
add_message(attrs)
click to toggle source
# File lib/chatbox/memory_store.rb, line 9 def add_message(attrs) attrs = attrs.merge id: id_generator.(), read: false attrs_list << attrs end
find_message(id)
click to toggle source
# File lib/chatbox/memory_store.rb, line 26 def find_message(id) if attrs = attrs_list.detect { |attrs| attrs[:id] == id } Record.new attrs end end
find_messages_by_from_id(id)
click to toggle source
# File lib/chatbox/memory_store.rb, line 36 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)
click to toggle source
# File lib/chatbox/memory_store.rb, line 32 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)
click to toggle source
# File lib/chatbox/memory_store.rb, line 16 def mark_message_read!(id) attrs_list.detect { |attrs| attrs[:id] == id }.merge! read: true end
mark_message_unread!(id)
click to toggle source
# File lib/chatbox/memory_store.rb, line 20 def mark_message_unread!(id) attrs_list.detect { |attrs| attrs[:id] == id }.merge! read: false end
Private Instance Methods
attrs_list()
click to toggle source
# File lib/chatbox/memory_store.rb, line 44 def attrs_list @attrs_list ||= [] end