Add Model/Repository postfix to all class and file names
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
18
bbs.rb
18
bbs.rb
@@ -2,15 +2,15 @@
|
|||||||
|
|
||||||
require 'bbs'
|
require 'bbs'
|
||||||
require 'time'
|
require 'time'
|
||||||
require_relative 'lib/repository/online_users'
|
require_relative 'lib/repository/online_users_repository'
|
||||||
require_relative 'lib/repository/message_board'
|
require_relative 'lib/repository/message_board_repository'
|
||||||
require_relative 'lib/repository/wiki'
|
require_relative 'lib/repository/wiki_repository'
|
||||||
require_relative 'lib/repository/catalog'
|
require_relative 'lib/repository/catalog_repository'
|
||||||
|
|
||||||
ONLINE = OnlineUsers.new
|
ONLINE = OnlineUsersRepository.new
|
||||||
MESSAGES = MessageBoard.new(ENV.fetch('MESSAGES_PATH', 'data/messages.dat'))
|
MESSAGES = MessageBoardRepository.new(ENV.fetch('MESSAGES_PATH', 'data/messages.dat'))
|
||||||
WIKI = WikiClient.new(token: ENV['WEBAPP_WIKIJS_TOKEN'])
|
WIKI = WikiRepository.new(token: ENV['WEBAPP_WIKIJS_TOKEN'])
|
||||||
CATALOG = CatalogClient.new
|
CATALOG = CatalogRepository.new
|
||||||
|
|
||||||
module C
|
module C
|
||||||
RESET = "\e[0m"
|
RESET = "\e[0m"
|
||||||
@@ -147,7 +147,7 @@ BBS.configure do |c|
|
|||||||
end
|
end
|
||||||
|
|
||||||
out << "\r\n #{C::GRAY}#{'─' * 66}#{C::RESET}\r\n"
|
out << "\r\n #{C::GRAY}#{'─' * 66}#{C::RESET}\r\n"
|
||||||
out << " #{C::GRAY}#{CatalogClient::GAMES_URL}#{C::RESET}\r\n\r\n"
|
out << " #{C::GRAY}#{CatalogRepository::GAMES_URL}#{C::RESET}\r\n\r\n"
|
||||||
out
|
out
|
||||||
end
|
end
|
||||||
wait_enter
|
wait_enter
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
class Game
|
class GameModel
|
||||||
attr_reader :title, :platform, :author, :desc,
|
attr_reader :title, :platform, :author, :desc,
|
||||||
:play_path, :download_path, :source_path, :docs_path,
|
:play_path, :download_path, :source_path, :docs_path,
|
||||||
:release_count
|
:release_count
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
# frozen_string_literal: true
|
|
||||||
|
|
||||||
Message = Struct.new(:timestamp, :username, :text)
|
|
||||||
3
lib/model/message_model.rb
Normal file
3
lib/model/message_model.rb
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
MessageModel = Struct.new(:timestamp, :username, :text)
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
# frozen_string_literal: true
|
|
||||||
|
|
||||||
WikiPage = Struct.new(:id, :path, :title, :description, :created_at, :locale, keyword_init: true)
|
|
||||||
3
lib/model/wiki_page_model.rb
Normal file
3
lib/model/wiki_page_model.rb
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
WikiPageModel = Struct.new(:id, :path, :title, :description, :created_at, :locale, keyword_init: true)
|
||||||
@@ -3,9 +3,9 @@
|
|||||||
require 'net/http'
|
require 'net/http'
|
||||||
require 'json'
|
require 'json'
|
||||||
require 'uri'
|
require 'uri'
|
||||||
require_relative '../model/game'
|
require_relative '../model/game_model'
|
||||||
|
|
||||||
class CatalogClient
|
class CatalogRepository
|
||||||
API_URL = 'https://games.teletype.hu/api/software'
|
API_URL = 'https://games.teletype.hu/api/software'
|
||||||
GAMES_URL = 'https://games.teletype.hu'
|
GAMES_URL = 'https://games.teletype.hu'
|
||||||
|
|
||||||
@@ -17,9 +17,9 @@ class CatalogClient
|
|||||||
http.read_timeout = 12
|
http.read_timeout = 12
|
||||||
data = JSON.parse(http.get(uri.path).body)
|
data = JSON.parse(http.get(uri.path).body)
|
||||||
entries = data.is_a?(Hash) ? (data['softwares'] || []) : data
|
entries = data.is_a?(Hash) ? (data['softwares'] || []) : data
|
||||||
entries.filter_map { |e| Game.new(e) if e.is_a?(Hash) }
|
entries.filter_map { |e| GameModel.new(e) if e.is_a?(Hash) }
|
||||||
rescue => e
|
rescue => e
|
||||||
warn "Catalog fetch error: #{e}"
|
warn "CatalogRepository fetch error: #{e}"
|
||||||
[]
|
[]
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -3,9 +3,9 @@
|
|||||||
require 'csv'
|
require 'csv'
|
||||||
require 'time'
|
require 'time'
|
||||||
require 'fileutils'
|
require 'fileutils'
|
||||||
require_relative '../model/message'
|
require_relative '../model/message_model'
|
||||||
|
|
||||||
class MessageBoard
|
class MessageBoardRepository
|
||||||
def initialize(path)
|
def initialize(path)
|
||||||
@path = path
|
@path = path
|
||||||
@messages = []
|
@messages = []
|
||||||
@@ -14,7 +14,7 @@ class MessageBoard
|
|||||||
end
|
end
|
||||||
|
|
||||||
def append(username, text)
|
def append(username, text)
|
||||||
msg = Message.new(Time.now.strftime('%m-%d %H:%M'), username, text)
|
msg = MessageModel.new(Time.now.strftime('%m-%d %H:%M'), username, text)
|
||||||
@mu.synchronize do
|
@mu.synchronize do
|
||||||
@messages << msg
|
@messages << msg
|
||||||
FileUtils.mkdir_p(File.dirname(@path))
|
FileUtils.mkdir_p(File.dirname(@path))
|
||||||
@@ -35,8 +35,8 @@ class MessageBoard
|
|||||||
|
|
||||||
def load_csv
|
def load_csv
|
||||||
return unless File.exist?(@path)
|
return unless File.exist?(@path)
|
||||||
CSV.foreach(@path) { |row| @messages << Message.new(*row) }
|
CSV.foreach(@path) { |row| @messages << MessageModel.new(*row) }
|
||||||
rescue => e
|
rescue => e
|
||||||
warn "MessageBoard load error: #{e}"
|
warn "MessageBoardRepository load error: #{e}"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
class OnlineUsers
|
class OnlineUsersRepository
|
||||||
def initialize
|
def initialize
|
||||||
@users = {}
|
@users = {}
|
||||||
@mu = Mutex.new
|
@mu = Mutex.new
|
||||||
@@ -3,9 +3,9 @@
|
|||||||
require 'net/http'
|
require 'net/http'
|
||||||
require 'json'
|
require 'json'
|
||||||
require 'uri'
|
require 'uri'
|
||||||
require_relative '../model/wiki_page'
|
require_relative '../model/wiki_page_model'
|
||||||
|
|
||||||
class WikiClient
|
class WikiRepository
|
||||||
BASE_URL = 'https://wiki.teletype.hu'
|
BASE_URL = 'https://wiki.teletype.hu'
|
||||||
|
|
||||||
def initialize(token: nil)
|
def initialize(token: nil)
|
||||||
@@ -19,7 +19,7 @@ class WikiClient
|
|||||||
}}}
|
}}}
|
||||||
GQL
|
GQL
|
||||||
(graphql(query).dig('data', 'pages', 'list') || []).map do |p|
|
(graphql(query).dig('data', 'pages', 'list') || []).map do |p|
|
||||||
WikiPage.new(
|
WikiPageModel.new(
|
||||||
id: p['id'],
|
id: p['id'],
|
||||||
path: p['path'],
|
path: p['path'],
|
||||||
title: p['title'],
|
title: p['title'],
|
||||||
@@ -29,7 +29,7 @@ class WikiClient
|
|||||||
)
|
)
|
||||||
end
|
end
|
||||||
rescue => e
|
rescue => e
|
||||||
warn "Wiki list error: #{e}"
|
warn "WikiRepository list error: #{e}"
|
||||||
[]
|
[]
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -37,7 +37,7 @@ class WikiClient
|
|||||||
query = "{ pages { single(id: #{page_id}) { content } } }"
|
query = "{ pages { single(id: #{page_id}) { content } } }"
|
||||||
graphql(query).dig('data', 'pages', 'single', 'content') || ''
|
graphql(query).dig('data', 'pages', 'single', 'content') || ''
|
||||||
rescue => e
|
rescue => e
|
||||||
warn "Wiki content error: #{e}"
|
warn "WikiRepository content error: #{e}"
|
||||||
''
|
''
|
||||||
end
|
end
|
||||||
|
|
||||||
Reference in New Issue
Block a user