Compare commits
21 Commits
e1f5bd3950
...
v0.2.1
Author | SHA1 | Date | |
---|---|---|---|
39f95575da | |||
6e1ab89209 | |||
9cd6c78741 | |||
5b730df803 | |||
0ce4a3ecee | |||
12ece12394 | |||
05c20b5811 | |||
bd822664b0 | |||
3f0efce0d8 | |||
eeedc57cd3 | |||
164eea1bde | |||
85fe3b0b38 | |||
519955e57a | |||
96b746822c | |||
eac833fd6d | |||
ad391c84a4 | |||
641c9315bc | |||
3a136865b0 | |||
|
f40d69a98d | ||
|
40cfdcc2a3 | ||
|
260d0d1268 |
3
.gitignore
vendored
3
.gitignore
vendored
@@ -65,3 +65,6 @@ node_modules/
|
||||
# Compiled assets
|
||||
public/css/
|
||||
public/js/
|
||||
|
||||
# Ignore production configuration files to protect against credential leaks
|
||||
config/production.yaml
|
||||
|
@@ -1,4 +1,6 @@
|
||||
require: rubocop-sequel
|
||||
plugins:
|
||||
- rubocop-rspec
|
||||
- rubocop-sequel
|
||||
|
||||
AllCops:
|
||||
NewCops: enable
|
||||
|
@@ -1,11 +1,32 @@
|
||||
pipeline:
|
||||
steps:
|
||||
setup:
|
||||
image: ruby:3.4
|
||||
env:
|
||||
RACK_ENV: testing
|
||||
commands:
|
||||
- gem install rake
|
||||
- bundle config set --local path "vendor/bundle"
|
||||
- bundle install
|
||||
- rake db:migrate
|
||||
|
||||
test_ruby34:
|
||||
image: ruby:3.4
|
||||
env:
|
||||
RACK_ENV: testing
|
||||
commands:
|
||||
- gem install rake
|
||||
- bundle config set --local path "vendor/bundle"
|
||||
- rake test:unit
|
||||
group: tests
|
||||
|
||||
style:
|
||||
image: ruby:3.4
|
||||
env:
|
||||
RACK_ENV: testing
|
||||
commands:
|
||||
- 'gem install rake'
|
||||
- 'bundle config set --local path "vendor/bundle"'
|
||||
- 'bundle install'
|
||||
- 'rake test:rubocop'
|
||||
- gem install rake
|
||||
- bundle config set --local path "vendor/bundle"
|
||||
- rake test:lint
|
||||
|
||||
gitea_release:
|
||||
image: plugins/gitea-release
|
||||
@@ -15,5 +36,5 @@ pipeline:
|
||||
base_url: https://git.metaunix.net
|
||||
title: "${CI_COMMIT_TAG}"
|
||||
when:
|
||||
event: tag
|
||||
|
||||
event:
|
||||
- tag
|
||||
|
7
Gemfile
7
Gemfile
@@ -15,5 +15,12 @@ group :development, :test do
|
||||
|
||||
# rubocop and extensions for code style
|
||||
gem 'rubocop'
|
||||
gem 'rubocop-rspec'
|
||||
gem 'rubocop-sequel'
|
||||
end
|
||||
|
||||
group :test do
|
||||
gem 'rspec'
|
||||
gem 'rack-test'
|
||||
gem 'database_cleaner-sequel'
|
||||
end
|
||||
|
27
Gemfile.lock
27
Gemfile.lock
@@ -4,6 +4,11 @@ GEM
|
||||
ast (2.4.3)
|
||||
base64 (0.3.0)
|
||||
bigdecimal (3.2.2)
|
||||
database_cleaner-core (2.0.1)
|
||||
database_cleaner-sequel (2.0.2)
|
||||
database_cleaner-core (~> 2.0.0)
|
||||
sequel
|
||||
diff-lcs (1.6.2)
|
||||
ffi (1.17.2-aarch64-linux-gnu)
|
||||
ffi (1.17.2-aarch64-linux-musl)
|
||||
ffi (1.17.2-arm-linux-gnu)
|
||||
@@ -41,6 +46,8 @@ GEM
|
||||
rack-session (2.1.1)
|
||||
base64 (>= 0.1.0)
|
||||
rack (>= 3.0.0)
|
||||
rack-test (2.2.0)
|
||||
rack (>= 1.3)
|
||||
rainbow (3.1.1)
|
||||
rb-fsevent (0.11.2)
|
||||
rb-inotify (0.11.1)
|
||||
@@ -48,6 +55,19 @@ GEM
|
||||
regexp_parser (2.10.0)
|
||||
rerun (0.14.0)
|
||||
listen (~> 3.0)
|
||||
rspec (3.13.1)
|
||||
rspec-core (~> 3.13.0)
|
||||
rspec-expectations (~> 3.13.0)
|
||||
rspec-mocks (~> 3.13.0)
|
||||
rspec-core (3.13.5)
|
||||
rspec-support (~> 3.13.0)
|
||||
rspec-expectations (3.13.5)
|
||||
diff-lcs (>= 1.2.0, < 2.0)
|
||||
rspec-support (~> 3.13.0)
|
||||
rspec-mocks (3.13.5)
|
||||
diff-lcs (>= 1.2.0, < 2.0)
|
||||
rspec-support (~> 3.13.0)
|
||||
rspec-support (3.13.4)
|
||||
rubocop (1.76.1)
|
||||
json (~> 2.3)
|
||||
language_server-protocol (~> 3.17.0.2)
|
||||
@@ -62,6 +82,9 @@ GEM
|
||||
rubocop-ast (1.45.1)
|
||||
parser (>= 3.3.7.2)
|
||||
prism (~> 1.4)
|
||||
rubocop-rspec (3.6.0)
|
||||
lint_roller (~> 1.1)
|
||||
rubocop (~> 1.72, >= 1.72.1)
|
||||
rubocop-sequel (0.4.1)
|
||||
lint_roller (~> 1.1)
|
||||
rubocop (>= 1.72.1, < 2)
|
||||
@@ -110,10 +133,14 @@ PLATFORMS
|
||||
x86_64-linux-musl
|
||||
|
||||
DEPENDENCIES
|
||||
database_cleaner-sequel
|
||||
logger
|
||||
puma (~> 6.6)
|
||||
rack-test
|
||||
rerun
|
||||
rspec
|
||||
rubocop
|
||||
rubocop-rspec
|
||||
rubocop-sequel
|
||||
sequel (~> 5.92)
|
||||
sinatra (~> 4.1)
|
||||
|
44
README.md
44
README.md
@@ -1,5 +1,7 @@
|
||||
# Game Data
|
||||
|
||||

|
||||
|
||||
Web-based tool to store and organize PC hardware gaming benchmarks.
|
||||
|
||||
## Project Goals
|
||||
@@ -7,28 +9,58 @@ Web-based tool to store and organize PC hardware gaming benchmarks.
|
||||
The goals of this project are to:
|
||||
|
||||
* Record benchmarking results from multiple devices - e.g. log from a laptop or a phone.
|
||||
* Group results into tests - it's good practice to run a benchmark multiple times for accuracy.
|
||||
* Group results into tests to keep track of different testing configurations.
|
||||
* Encourage running tests multiple times - it's good practice to run a benchmark multiple times for accuracy.
|
||||
* Create comparisons of hardware tests to compare performance.
|
||||
* Generate graphs of hardware comparisons for usage in videos and articles.
|
||||
|
||||
## Requirements
|
||||
|
||||
Game Data runs on Ruby, and takes advantage of Bundler to manage code dependencies and Rake to run various tasks for maintaining the app. You can install them globally like so:
|
||||
Game Data runs on Ruby, and takes advantage of [Bundler](https://bundler.io/) to manage code dependencies and [Rake](https://ruby.github.io/rake/) to run various tasks for maintaining the app. You can install them globally like so:
|
||||
|
||||
Debian/Ubuntu: `apt install -y ruby ruby-bundler rake`
|
||||
RedHat and clones: `dnf install -y ruby rubygem-bundler rubygem-rake`
|
||||
|
||||
## Production Deployment
|
||||
|
||||
**TBD**
|
||||
|
||||
## Development
|
||||
|
||||
Install dependencies via bundler:
|
||||
### Via Docker
|
||||
|
||||
If you'd prefer not to install dependencies and such to your local OS, you can do the development via Docker. The scripts provided in `bin/` will build Docker images for running the Ruby app and building the front-end assets via Gulp. *Both containers will automatically watch for changes.*
|
||||
|
||||
**Note:** Using the scripts below, the Docker images will remove themselves when stopped. This is to make clean up a bit more streamlined.
|
||||
|
||||
1. [Install Docker](https://docs.docker.com/engine/install/) for your OS.
|
||||
|
||||
2. Build the docker images for Ruby and Gulp:
|
||||
|
||||
`bin/docker-build.sh`
|
||||
|
||||
3. Run the docker images:
|
||||
|
||||
`bin/docker-run.sh`
|
||||
|
||||
4. If everything is running successfully you can open your browser and go to https://localhost:9292.
|
||||
|
||||
### Local/Native Development
|
||||
|
||||
1. Install dependencies via bundler:
|
||||
|
||||
`bundle install`
|
||||
|
||||
Perform database migrations:
|
||||
2. Perform database migrations:
|
||||
|
||||
`rake db:migrate`
|
||||
|
||||
Run the server in development with auto-reloading:
|
||||
3. Run the server in development with auto-reloading:
|
||||
|
||||
`rake server:dev`
|
||||
|
||||
If everything is running successfully you can open your browser and go to https://localhost:9292.
|
||||
4. If everything is running successfully you can open your browser and go to https://localhost:9292.
|
||||
|
||||
## License
|
||||
|
||||
This project is available under the BSD 2-Clause license.
|
||||
|
22
Rakefile
22
Rakefile
@@ -3,18 +3,22 @@ require 'bundler/setup'
|
||||
namespace :db do
|
||||
desc 'Run migrations'
|
||||
task :migrate, [:version] do |t, args|
|
||||
require "sequel/core"
|
||||
require 'sequel/core'
|
||||
# load configuration
|
||||
require_relative 'src/config'
|
||||
conf = Config.new()
|
||||
|
||||
Sequel.extension :migration
|
||||
version = args[:version].to_i if args[:version]
|
||||
Sequel.connect('sqlite://data/gamedata.db') do |db|
|
||||
Sequel::Migrator.run(db, "db/migrations", target: version)
|
||||
Sequel.connect(adapter: conf.get('database.adapter'), database: conf.get('database.database')) do |db|
|
||||
Sequel::Migrator.run(db, 'db/migrations', target: version)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
namespace :server do
|
||||
task :start do
|
||||
ENV['APP_ENV'] = 'production'
|
||||
ENV['RACK_ENV'] = 'production'
|
||||
system("puma")
|
||||
end
|
||||
|
||||
@@ -24,8 +28,12 @@ namespace :server do
|
||||
end
|
||||
|
||||
namespace :test do
|
||||
task :rubocop do
|
||||
system("rubocop src/")
|
||||
task :unit do
|
||||
ENV['RACK_ENV'] = 'testing'
|
||||
system("rspec")
|
||||
end
|
||||
|
||||
task :lint do
|
||||
system("rubocop src/ spec/")
|
||||
end
|
||||
end
|
||||
|
||||
|
@@ -1,7 +1,5 @@
|
||||
# Load application config
|
||||
require_relative 'src/config.rb'
|
||||
$conf = Config.new(File.join(__dir__, 'config/defaults.yaml'))
|
||||
|
||||
root = ::File.dirname(__FILE__)
|
||||
require ::File.join( root, 'src', 'app' )
|
||||
require ::File.join( root, 'src', 'server' )
|
||||
run GameData.new
|
||||
|
@@ -1,6 +1,6 @@
|
||||
database:
|
||||
adapter: 'sqlite'
|
||||
database: 'data/gamedata.db'
|
||||
server:
|
||||
host: '0.0.0.0'
|
||||
port: '9292'
|
||||
|
||||
testing:
|
||||
minimum_results_required: 3
|
||||
|
3
config/development.yaml
Normal file
3
config/development.yaml
Normal file
@@ -0,0 +1,3 @@
|
||||
database:
|
||||
adapter: 'sqlite'
|
||||
database: 'data/gamedata.db'
|
@@ -3,7 +3,9 @@ directory app_dir
|
||||
|
||||
environment ENV.fetch('RACK_ENV', 'development')
|
||||
|
||||
bind 'tcp://0.0.0.0:9292'
|
||||
require_relative '../src/config'
|
||||
conf = Config.new()
|
||||
|
||||
bind "tcp://#{conf.get('server.host')}:#{conf.get('server.port')}"
|
||||
workers 2
|
||||
threads 1, 5
|
||||
|
||||
|
3
config/testing.yaml
Normal file
3
config/testing.yaml
Normal file
@@ -0,0 +1,3 @@
|
||||
database:
|
||||
adapter: 'sqlite'
|
||||
database: 'data/gamedata_testing.db'
|
44
spec/controllers/benchmark_controller_spec.rb
Normal file
44
spec/controllers/benchmark_controller_spec.rb
Normal file
@@ -0,0 +1,44 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require_relative '../spec_helper'
|
||||
|
||||
RSpec.describe(BenchmarkController) do
|
||||
# /benchmark - redirects to /benchmark/list
|
||||
describe 'GET /benchmark' do
|
||||
before { get '/benchmark' }
|
||||
|
||||
it 'Benchmark base route is a redirect' do
|
||||
expect(last_response).to(be_redirect)
|
||||
end
|
||||
|
||||
it 'Benchmark base route Location header points to /benchmark/list' do
|
||||
expect(last_response['Location']).to(eq("#{BASE_URL}/benchmark/list"))
|
||||
end
|
||||
end
|
||||
|
||||
# /benchmark/list - displays a table of benchmarks
|
||||
describe 'GET /benchmark/list' do
|
||||
before { get '/benchmark/list' }
|
||||
|
||||
it 'Benchmark list page returns 200.' do
|
||||
expect(last_response).to(be_ok)
|
||||
end
|
||||
|
||||
it "Benchmark list page contains 'List of benchmarks' on page." do
|
||||
expect(last_response.body).to(include('List of benchmarks'))
|
||||
end
|
||||
end
|
||||
|
||||
# /benchmark/add - form for adding benchmark
|
||||
describe 'GET /benchmark/add' do
|
||||
before { get '/benchmark/add' }
|
||||
|
||||
it 'Benchmark add page returns 200.' do
|
||||
expect(last_response).to(be_ok)
|
||||
end
|
||||
|
||||
it "Benchmark add page contains 'Add new benchmark' on page." do
|
||||
expect(last_response.body).to(include('Add new benchmark'))
|
||||
end
|
||||
end
|
||||
end
|
44
spec/controllers/hardware_controller_spec.rb
Normal file
44
spec/controllers/hardware_controller_spec.rb
Normal file
@@ -0,0 +1,44 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require_relative '../spec_helper'
|
||||
|
||||
RSpec.describe(HardwareController) do
|
||||
# /hardware - redirects to /hardware/list
|
||||
describe 'GET /hardware' do
|
||||
before { get '/hardware' }
|
||||
|
||||
it 'Hardware base route is a redirect' do
|
||||
expect(last_response).to(be_redirect)
|
||||
end
|
||||
|
||||
it 'Hardware base route Location header points to /hardware/list' do
|
||||
expect(last_response['Location']).to(eq("#{BASE_URL}/hardware/list"))
|
||||
end
|
||||
end
|
||||
|
||||
# /hardware/list - displays a table of hardwares
|
||||
describe 'GET /hardware/list' do
|
||||
before { get '/hardware/list' }
|
||||
|
||||
it 'Hardware list page returns 200.' do
|
||||
expect(last_response).to(be_ok)
|
||||
end
|
||||
|
||||
it "Hardware list page contains 'List of hardware' on page." do
|
||||
expect(last_response.body).to(include('List of hardware'))
|
||||
end
|
||||
end
|
||||
|
||||
# /hardware/add - form for adding hardware
|
||||
describe 'GET /hardware/add' do
|
||||
before { get '/hardware/add' }
|
||||
|
||||
it 'Hardware add page returns 200.' do
|
||||
expect(last_response).to(be_ok)
|
||||
end
|
||||
|
||||
it "Hardware add page contains 'Add new hardware' on page." do
|
||||
expect(last_response.body).to(include('Add new hardware'))
|
||||
end
|
||||
end
|
||||
end
|
21
spec/controllers/index_controller_spec.rb
Normal file
21
spec/controllers/index_controller_spec.rb
Normal file
@@ -0,0 +1,21 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require_relative '../spec_helper'
|
||||
|
||||
RSpec.describe(IndexController) do
|
||||
describe 'GET /' do
|
||||
before { get '/' }
|
||||
|
||||
it 'Dashboard returns 200.' do
|
||||
expect(last_response).to(be_ok)
|
||||
end
|
||||
|
||||
it "Dashboard contains 'Game Data' on page (nav bar should be loaded)." do
|
||||
expect(last_response.body).to(include('Game Data'))
|
||||
end
|
||||
|
||||
it "Dashboard contains 'Ruby version' on page (footer should be loaded)." do
|
||||
expect(last_response.body).to(include('Ruby version'))
|
||||
end
|
||||
end
|
||||
end
|
17
spec/controllers/reports_controller_spec.rb
Normal file
17
spec/controllers/reports_controller_spec.rb
Normal file
@@ -0,0 +1,17 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require_relative '../spec_helper'
|
||||
|
||||
RSpec.describe(ReportsController) do
|
||||
describe 'GET /report' do
|
||||
before { get '/report' }
|
||||
|
||||
it 'Reports page returns 200.' do
|
||||
expect(last_response).to(be_ok)
|
||||
end
|
||||
|
||||
it "Reports page contains 'Generate report' on page." do
|
||||
expect(last_response.body).to(include('Generate report'))
|
||||
end
|
||||
end
|
||||
end
|
44
spec/controllers/test_controller_spec.rb
Normal file
44
spec/controllers/test_controller_spec.rb
Normal file
@@ -0,0 +1,44 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require_relative '../spec_helper'
|
||||
|
||||
RSpec.describe(TestController) do
|
||||
# /test - redirects to /test/list
|
||||
describe 'GET /test' do
|
||||
before { get '/test' }
|
||||
|
||||
it 'Test base route is a redirect' do
|
||||
expect(last_response).to(be_redirect)
|
||||
end
|
||||
|
||||
it 'Test base route Location header points to /test/list' do
|
||||
expect(last_response['Location']).to(eq("#{BASE_URL}/test/list"))
|
||||
end
|
||||
end
|
||||
|
||||
# /test/list - displays a table of tests
|
||||
describe 'GET /test/list' do
|
||||
before { get '/test/list' }
|
||||
|
||||
it 'Test list page returns 200.' do
|
||||
expect(last_response).to(be_ok)
|
||||
end
|
||||
|
||||
it "Test list page contains 'List of tests' on page." do
|
||||
expect(last_response.body).to(include('List of tests'))
|
||||
end
|
||||
end
|
||||
|
||||
# /test/add - form for adding test
|
||||
describe 'GET /test/add' do
|
||||
before { get '/test/add' }
|
||||
|
||||
it 'Test add page returns 200.' do
|
||||
expect(last_response).to(be_ok)
|
||||
end
|
||||
|
||||
it "Test add page contains 'Add new test' on page." do
|
||||
expect(last_response.body).to(include('Add new test'))
|
||||
end
|
||||
end
|
||||
end
|
27
spec/models/benchmark_model_spec.rb
Normal file
27
spec/models/benchmark_model_spec.rb
Normal file
@@ -0,0 +1,27 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require_relative '../spec_helper'
|
||||
|
||||
RSpec.describe(Benchmark) do
|
||||
describe 'Benchmark Creation' do
|
||||
it 'Benchmark creation updates model count.' do
|
||||
expect do
|
||||
described_class.create(name: 'Test Benchmark', scoring: 'fps')
|
||||
end.to(change(described_class, :count).by(1))
|
||||
end
|
||||
end
|
||||
|
||||
describe 'Benchmark Read' do
|
||||
before { described_class.create(name: 'Test Benchmark', scoring: 'fps') }
|
||||
|
||||
it 'Benchmark model has name.' do
|
||||
bench = described_class.first()
|
||||
expect(bench.name).to(eq('Test Benchmark'))
|
||||
end
|
||||
|
||||
it 'Benchmark model has scoring.' do
|
||||
bench = described_class.first()
|
||||
expect(bench.scoring).to(eq('fps'))
|
||||
end
|
||||
end
|
||||
end
|
25
spec/models/hardware_model_spec.rb
Normal file
25
spec/models/hardware_model_spec.rb
Normal file
@@ -0,0 +1,25 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require_relative '../spec_helper'
|
||||
|
||||
RSpec.describe(Hardware) do
|
||||
describe 'Hardware Creation' do
|
||||
it 'Hardware creation updates model count.' do
|
||||
expect { described_class.create(name: 'Test Hardware', type: 'gpu') }.to(change(described_class, :count).by(1))
|
||||
end
|
||||
end
|
||||
|
||||
describe 'Hardware Read' do
|
||||
before { described_class.create(name: 'Test Hardware', type: 'gpu') }
|
||||
|
||||
it 'Hardware model has name.' do
|
||||
hardware = described_class.first()
|
||||
expect(hardware.name).to(eq('Test Hardware'))
|
||||
end
|
||||
|
||||
it 'Hardware model has scoring.' do
|
||||
hardware = described_class.first()
|
||||
expect(hardware.type).to(eq('gpu'))
|
||||
end
|
||||
end
|
||||
end
|
36
spec/models/test_model_spec.rb
Normal file
36
spec/models/test_model_spec.rb
Normal file
@@ -0,0 +1,36 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require_relative '../spec_helper'
|
||||
|
||||
RSpec.describe(Test) do
|
||||
describe 'Test Creation' do
|
||||
it 'Test creation updates model count.' do
|
||||
expect { described_class.create(name: 'Test Test') }.to(change(described_class, :count).by(1))
|
||||
end
|
||||
end
|
||||
|
||||
describe 'Test Read' do
|
||||
before do
|
||||
described_class.create(name: 'Test Test')
|
||||
end
|
||||
|
||||
it 'Test model has name.' do
|
||||
tst = described_class.first()
|
||||
expect(tst.name).to(eq('Test Test'))
|
||||
end
|
||||
end
|
||||
|
||||
describe 'Test one-to-many association with Hardware' do
|
||||
it 'Test model has Hardware associated with it.' do
|
||||
hardware = Hardware.create(name: 'Test Hardware', type: 'gpu')
|
||||
tst = described_class.create(name: 'Test Test', hardware_id: hardware.id)
|
||||
expect(tst.hardware).to(eq(hardware))
|
||||
end
|
||||
|
||||
it 'Test model\'s hardware has name set.' do
|
||||
hardware = Hardware.create(name: 'Test Hardware', type: 'gpu')
|
||||
tst = described_class.create(name: 'Test Test', hardware_id: hardware.id)
|
||||
expect(tst.hardware.name).to(eq('Test Hardware'))
|
||||
end
|
||||
end
|
||||
end
|
35
spec/spec_helper.rb
Normal file
35
spec/spec_helper.rb
Normal file
@@ -0,0 +1,35 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
ENV['APP_ENV'] = 'test'
|
||||
|
||||
require_relative '../src/server'
|
||||
require 'rspec'
|
||||
require 'rack/test'
|
||||
require 'database_cleaner/sequel'
|
||||
|
||||
# setting this here so all redirect tests can reference the same base URL
|
||||
BASE_URL = 'http://example.org'
|
||||
|
||||
module RSpecMixin
|
||||
|
||||
include Rack::Test::Methods
|
||||
|
||||
def app
|
||||
GameData
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
RSpec.configure do |config|
|
||||
config.include(RSpecMixin)
|
||||
|
||||
config.before(:suite) do
|
||||
DatabaseCleaner.strategy = :transaction
|
||||
end
|
||||
|
||||
config.around do |suite|
|
||||
DatabaseCleaner.cleaning do
|
||||
suite.run
|
||||
end
|
||||
end
|
||||
end
|
41
src/app.rb
41
src/app.rb
@@ -1,41 +0,0 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'sinatra/base'
|
||||
require 'sequel'
|
||||
require 'sqlite3'
|
||||
|
||||
# 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 in routes (must happen after Sequel is loaded!)
|
||||
require_relative 'routes/api1'
|
||||
require_relative 'routes/benchmark'
|
||||
require_relative 'routes/hardware'
|
||||
require_relative 'routes/index'
|
||||
require_relative 'routes/reports'
|
||||
require_relative 'routes/result'
|
||||
require_relative 'routes/test'
|
||||
|
||||
# GameData - main app that gets launched
|
||||
# - inherits from Sinatra::Base to instantiate the server
|
||||
# - sets up some base app configuration
|
||||
# - registers route classes with the base app
|
||||
class GameData < Sinatra::Base
|
||||
|
||||
enable :sessions
|
||||
|
||||
# Set up static file serving
|
||||
enable :static
|
||||
set :public_folder, File.join(__dir__, '/../public')
|
||||
|
||||
use IndexRoutes
|
||||
use HardwareRoutes
|
||||
use BenchmarkRoutes
|
||||
use TestRoutes
|
||||
use ResultRoutes
|
||||
use ReportsRoutes
|
||||
use APIv1Routes
|
||||
|
||||
end
|
@@ -2,6 +2,6 @@
|
||||
|
||||
module AppInfo
|
||||
|
||||
VERSION = '0.1.1'
|
||||
VERSION = '0.2.1'
|
||||
|
||||
end
|
||||
|
@@ -6,8 +6,9 @@ require 'yaml'
|
||||
class Config
|
||||
|
||||
DEFAULT_CONFIG = 'config/defaults.yaml'
|
||||
ENVIRONMENT_CONFIG = ENV.fetch('RACK_ENV', 'development')
|
||||
|
||||
def initialize(config_path)
|
||||
def initialize(config_path = "config/#{ENVIRONMENT_CONFIG}.yaml")
|
||||
@data = YAML.load_file(DEFAULT_CONFIG)
|
||||
|
||||
# merge in user-defined configuration if it exists
|
||||
|
@@ -2,13 +2,13 @@
|
||||
|
||||
require 'sinatra/json'
|
||||
|
||||
require_relative '../server'
|
||||
require_relative 'base_controller'
|
||||
require_relative '../models/benchmark'
|
||||
require_relative '../models/test'
|
||||
require_relative '../models/result'
|
||||
|
||||
# /api/v1 routes
|
||||
class APIv1Routes < Server
|
||||
class APIv1Controller < BaseController
|
||||
|
||||
get '/api/v1/benchmark/details' do
|
||||
benchmark_id = params[:benchmark_id]
|
15
src/controllers/base_controller.rb
Normal file
15
src/controllers/base_controller.rb
Normal file
@@ -0,0 +1,15 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'sinatra/base'
|
||||
|
||||
# BaseController - base modular Sinatra app class
|
||||
class BaseController < Sinatra::Base
|
||||
|
||||
# Register view helpers
|
||||
require_relative '../helpers'
|
||||
helpers Helpers
|
||||
|
||||
# Set up our view engine
|
||||
set :views, File.join(settings.root, '/../../views')
|
||||
|
||||
end
|
@@ -1,12 +1,16 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require_relative '../server'
|
||||
require_relative 'base_controller'
|
||||
require_relative '../models/benchmark'
|
||||
|
||||
# /benchmark routes
|
||||
class BenchmarkRoutes < Server
|
||||
class BenchmarkController < BaseController
|
||||
|
||||
get '/benchmark' do
|
||||
redirect('/benchmark/list')
|
||||
end
|
||||
|
||||
get '/benchmark/list' do
|
||||
benchmarks = Benchmark.reverse(:updated_at).limit(10).all()
|
||||
|
||||
erb :'benchmark/index', locals: {
|
@@ -1,13 +1,17 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require_relative '../server'
|
||||
require_relative 'base_controller'
|
||||
require_relative '../models/hardware'
|
||||
require_relative '../models/benchmark'
|
||||
|
||||
# /hardware routes
|
||||
class HardwareRoutes < Server
|
||||
class HardwareController < BaseController
|
||||
|
||||
get '/hardware' do
|
||||
redirect('/hardware/list')
|
||||
end
|
||||
|
||||
get '/hardware/list' do
|
||||
hardware = Hardware.reverse(:updated_at).limit(10).all()
|
||||
|
||||
erb :'hardware/index', locals: {
|
@@ -1,10 +1,10 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require_relative '../server'
|
||||
require_relative 'base_controller'
|
||||
require_relative '../models/test'
|
||||
|
||||
# / (top-level) routes
|
||||
class IndexRoutes < Server
|
||||
class IndexController < BaseController
|
||||
|
||||
get '/' do
|
||||
tests = Test.reverse(:updated_at).limit(10).all()
|
@@ -2,13 +2,13 @@
|
||||
|
||||
require 'sinatra/json'
|
||||
|
||||
require_relative '../server'
|
||||
require_relative 'base_controller'
|
||||
require_relative '../models/benchmark'
|
||||
require_relative '../models/result'
|
||||
require_relative '../models/test'
|
||||
|
||||
# /reports routes
|
||||
class ReportsRoutes < Server
|
||||
class ReportsController < BaseController
|
||||
|
||||
get '/report' do
|
||||
benchmarks = Benchmark.order(:name).all()
|
@@ -1,10 +1,10 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require_relative '../server'
|
||||
require_relative 'base_controller'
|
||||
require_relative '../models/result'
|
||||
|
||||
# /result routes
|
||||
class ResultRoutes < Server
|
||||
class ResultController < BaseController
|
||||
|
||||
post '/result/add' do
|
||||
result_minimum = params[:result_minimum] if params.key?(:result_minimum)
|
@@ -1,14 +1,18 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require_relative '../server'
|
||||
require_relative 'base_controller'
|
||||
require_relative '../models/benchmark'
|
||||
require_relative '../models/hardware'
|
||||
require_relative '../models/test'
|
||||
|
||||
# /test routes
|
||||
class TestRoutes < Server
|
||||
class TestController < BaseController
|
||||
|
||||
get '/test' do
|
||||
redirect('/test/list')
|
||||
end
|
||||
|
||||
get '/test/list' do
|
||||
tests = Test.reverse(:updated_at).limit(10).all()
|
||||
|
||||
erb :'test/index', locals: {
|
45
src/server.rb
Executable file → Normal file
45
src/server.rb
Executable file → Normal file
@@ -1,15 +1,46 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'sinatra/base'
|
||||
require 'sequel'
|
||||
require 'sqlite3'
|
||||
|
||||
# Server - base modular Sinatra app class
|
||||
class Server < Sinatra::Base
|
||||
require_relative 'config'
|
||||
|
||||
# Register view helpers
|
||||
require_relative 'helpers'
|
||||
helpers Helpers
|
||||
# Load configuration from environment config file
|
||||
$conf = Config.new()
|
||||
|
||||
# Set up our view engine
|
||||
set :views, File.join(settings.root, '/../views')
|
||||
# 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 in routes (must happen after Sequel is loaded!)
|
||||
require_relative 'controllers/api1'
|
||||
require_relative 'controllers/benchmark'
|
||||
require_relative 'controllers/hardware'
|
||||
require_relative 'controllers/index'
|
||||
require_relative 'controllers/reports'
|
||||
require_relative 'controllers/result'
|
||||
require_relative 'controllers/test'
|
||||
|
||||
# GameData - main app that gets launched
|
||||
# - inherits from Sinatra::Base to instantiate the server
|
||||
# - sets up some base app configuration
|
||||
# - registers route classes with the base app
|
||||
class GameData < Sinatra::Base
|
||||
|
||||
enable :sessions
|
||||
|
||||
# Set up static file serving
|
||||
enable :static
|
||||
set :public_folder, File.join(__dir__, '/../public')
|
||||
|
||||
use IndexController
|
||||
use HardwareController
|
||||
use BenchmarkController
|
||||
use TestController
|
||||
use ResultController
|
||||
use ReportsController
|
||||
use APIv1Controller
|
||||
|
||||
end
|
||||
|
@@ -1,3 +1,9 @@
|
||||
<div class="row">
|
||||
<div class="col-12">
|
||||
<h1>Generate report</h1>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<form class="col-12" action="/reports" method="post">
|
||||
<div class="row mb-3">
|
||||
|
Reference in New Issue
Block a user