Switched over to a modular Sinatra app layout
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful

This commit is contained in:
Gregory Ballantine
2025-08-12 13:54:25 -04:00
parent c74ca114d8
commit dd8e419e52
10 changed files with 53 additions and 23 deletions

View File

@@ -3,5 +3,5 @@ require_relative 'src/config.rb'
$conf = Config.new(File.join(__dir__, 'config/defaults.yaml')) $conf = Config.new(File.join(__dir__, 'config/defaults.yaml'))
root = ::File.dirname(__FILE__) root = ::File.dirname(__FILE__)
require ::File.join( root, 'src', 'server' ) require ::File.join( root, 'src', 'app' )
run GameData.new run GameData.new

30
src/app.rb Normal file
View File

@@ -0,0 +1,30 @@
# frozen_string_literal: true
require 'sinatra/base'
require 'sequel'
require 'sqlite3'
require_relative 'appinfo'
# Load the Sequel timestamps plugin
Sequel::Model.plugin(:timestamps)
# Initialize Sequel gem for database actions
DB = Sequel.connect(adapter: $conf.get('database.adapter'), database: $conf.get('database.database'))
# Load models
require_relative 'models/init'
# Load the routes
require_relative 'routes/init'
class GameData < Server
use IndexRoutes
use HardwareRoutes
use BenchmarkRoutes
use TestRoutes
use ResultRoutes
use ReportsRoutes
use APIv1Routes
end

View File

@@ -1,7 +1,9 @@
# frozen_string_literal: true # frozen_string_literal: true
require_relative '../server'
# /api/v1 routes # /api/v1 routes
class GameData < Sinatra::Base class APIv1Routes < Server
get '/api/v1/benchmark/details' do get '/api/v1/benchmark/details' do
benchmark_id = params[:benchmark_id] benchmark_id = params[:benchmark_id]

View File

@@ -1,7 +1,9 @@
# frozen_string_literal: true # frozen_string_literal: true
require_relative '../server'
# /benchmark routes # /benchmark routes
class GameData < Sinatra::Base class BenchmarkRoutes < Server
get '/benchmark' do get '/benchmark' do
benchmarks = Benchmark.reverse(:updated_at).limit(10).all() benchmarks = Benchmark.reverse(:updated_at).limit(10).all()

View File

@@ -1,7 +1,9 @@
# frozen_string_literal: true # frozen_string_literal: true
require_relative '../server'
# /hardware routes # /hardware routes
class GameData < Sinatra::Base class HardwareRoutes < Server
get '/hardware' do get '/hardware' do
hardware = Hardware.reverse(:updated_at).limit(10).all() hardware = Hardware.reverse(:updated_at).limit(10).all()

View File

@@ -1,7 +1,9 @@
# frozen_string_literal: true # frozen_string_literal: true
require_relative '../server'
# / (top-level) routes # / (top-level) routes
class GameData < Sinatra::Base class IndexRoutes < Server
get '/' do get '/' do
tests = Test.reverse(:updated_at).limit(10).all() tests = Test.reverse(:updated_at).limit(10).all()

View File

@@ -1,7 +1,9 @@
# frozen_string_literal: true # frozen_string_literal: true
require_relative '../server'
# /reports routes # /reports routes
class GameData < Sinatra::Base class ReportsRoutes < Server
get '/report' do get '/report' do
benchmarks = Benchmark.order(:name).all() benchmarks = Benchmark.order(:name).all()

View File

@@ -1,7 +1,9 @@
# frozen_string_literal: true # frozen_string_literal: true
require_relative '../server'
# /result routes # /result routes
class GameData < Sinatra::Base class ResultRoutes < Server
post '/result/add' do post '/result/add' do
result_minimum = params[:result_minimum] if params.key?(:result_minimum) result_minimum = params[:result_minimum] if params.key?(:result_minimum)

View File

@@ -1,7 +1,9 @@
# frozen_string_literal: true # frozen_string_literal: true
require_relative '../server'
# /test routes # /test routes
class GameData < Sinatra::Base class TestRoutes < Server
get '/test' do get '/test' do
tests = Test.reverse(:updated_at).limit(10).all() tests = Test.reverse(:updated_at).limit(10).all()

View File

@@ -2,18 +2,9 @@
require 'sinatra/base' require 'sinatra/base'
require 'sinatra/json' require 'sinatra/json'
require 'sequel'
require 'sqlite3'
require_relative 'appinfo'
# Load the Sequel timestamps plugin
Sequel::Model.plugin(:timestamps)
# Initialize Sequel gem for database actions
DB = Sequel.connect(adapter: $conf.get('database.adapter'), database: $conf.get('database.database'))
# Base app # Base app
class GameData < Sinatra::Base class Server < Sinatra::Base
enable :sessions enable :sessions
@@ -29,8 +20,3 @@ class GameData < Sinatra::Base
set :views, File.join(settings.root, '/../views') set :views, File.join(settings.root, '/../views')
end end
# Load routes
require_relative 'routes/init'
# Load models
require_relative 'models/init'