Introduce model/ and repository/ structure under lib/
Models: Message, WikiPage, Game (typed structs instead of raw hashes) Repositories: MessageBoard, OnlineUsers, WikiClient, CatalogClient bbs.rb uses attribute access (page.title, game.play_path, …) throughout Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
24
lib/repository/online_users.rb
Normal file
24
lib/repository/online_users.rb
Normal file
@@ -0,0 +1,24 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class OnlineUsers
|
||||
def initialize
|
||||
@users = {}
|
||||
@mu = Mutex.new
|
||||
end
|
||||
|
||||
def add(session_id, name)
|
||||
@mu.synchronize { @users[session_id] = name }
|
||||
end
|
||||
|
||||
def remove(session_id)
|
||||
@mu.synchronize { @users.delete(session_id) }
|
||||
end
|
||||
|
||||
def snapshot
|
||||
@mu.synchronize { @users.dup }
|
||||
end
|
||||
|
||||
def count
|
||||
@mu.synchronize { @users.size }
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user