add skeleton for models

main
Alpha Chen 2 years ago
commit b26b3cd908
Signed by: alpha
SSH Key Fingerprint: SHA256:3fOT8fiYQG/aK9ntivV3Bqtg8AYQ7q4nV6ZgihOA20g

@ -0,0 +1,15 @@
# frozen_string_literal: true
source "https://rubygems.org"
git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
gem "sequel"
gem "sqlite3"
group :development do
gem "minitest"
gem "rake"
gem "steep"
gem "typeprof"
end

@ -0,0 +1,71 @@
GEM
remote: https://rubygems.org/
specs:
activesupport (7.0.4)
concurrent-ruby (~> 1.0, >= 1.0.2)
i18n (>= 1.6, < 2)
minitest (>= 5.1)
tzinfo (~> 2.0)
ast (2.4.2)
concurrent-ruby (1.1.10)
csv (3.2.5)
ffi (1.15.5)
fileutils (1.6.0)
i18n (1.12.0)
concurrent-ruby (~> 1.0)
json (2.6.2)
language_server-protocol (3.17.0.1)
listen (3.7.1)
rb-fsevent (~> 0.10, >= 0.10.3)
rb-inotify (~> 0.9, >= 0.9.10)
logger (1.5.1)
minitest (5.16.3)
parallel (1.22.1)
parser (3.1.2.1)
ast (~> 2.4.1)
rainbow (3.1.1)
rake (13.0.6)
rb-fsevent (0.11.2)
rb-inotify (0.10.1)
ffi (~> 1.0)
rbs (2.7.0)
securerandom (0.2.0)
sequel (5.62.0)
sqlite3 (1.5.3-arm64-darwin)
steep (1.2.1)
activesupport (>= 5.1)
csv (>= 3.0.9)
fileutils (>= 1.1.0)
json (>= 2.1.0)
language_server-protocol (>= 3.15, < 4.0)
listen (~> 3.0)
logger (>= 1.3.0)
parallel (>= 1.0.0)
parser (>= 3.1)
rainbow (>= 2.2.2, < 4.0)
rbs (>= 2.7.0)
securerandom (>= 0.1)
strscan (>= 1.0.0)
terminal-table (>= 2, < 4)
strscan (3.0.4)
terminal-table (3.0.2)
unicode-display_width (>= 1.1.1, < 3)
typeprof (0.21.3)
rbs (>= 1.8.1)
tzinfo (2.0.5)
concurrent-ruby (~> 1.0)
unicode-display_width (2.3.0)
PLATFORMS
arm64-darwin-21
DEPENDENCIES
minitest
rake
sequel
sqlite3
steep
typeprof
BUNDLED WITH
2.3.18

@ -0,0 +1,27 @@
require "minitest/test_task"
require "sequel"
task default: :test
namespace :db do
desc "Run migrations"
task :migrate, [:version] do |t, args|
require "sequel/core"
Sequel.extension :migration
version = args[:version].to_i if args[:version]
Sequel.connect(ENV.fetch("DATABASE_URL")) do |db|
Sequel::Migrator.run(db, "db/migrations", target: version)
end
end
end
Minitest::TestTask.create(:test) do |t|
t.test_globs = ["test/**/test_*.rb"]
end
namespace :test do
desc "Run tests on Ruby file changes"
task :watch do
sh "fd .*.rb | entr -d rake test"
end
end

@ -0,0 +1,27 @@
# D = Steep::Diagnostic
#
# target :lib do
# signature "sig"
#
# check "lib" # Directory name
# check "Gemfile" # File name
# check "app/models/**/*.rb" # Glob
# # ignore "lib/templates/*.rb"
#
# # library "pathname", "set" # Standard libraries
# # library "strong_json" # Gems
#
# # configure_code_diagnostics(D::Ruby.strict) # `strict` diagnostics setting
# # configure_code_diagnostics(D::Ruby.lenient) # `lenient` diagnostics setting
# # configure_code_diagnostics do |hash| # You can setup everything yourself
# # hash[D::Ruby::NoMethod] = :information
# # end
# end
# target :test do
# signature "sig", "sig-private"
#
# check "test"
#
# # library "pathname", "set" # Standard libraries
# end

@ -0,0 +1,61 @@
Sequel.migration do
change do
create_table(:pools) do
primary_key :id
String :name, null: false
DateTime :created_at, null: false
DateTime :updated_at, null: false
end
create_table(:items) do
primary_key :id
foreign_key :pool_id, :pools
String :title, null: false
String :body, null: false
DateTime :created_at, null: false
DateTime :updated_at, null: false
end
create_table(:axes) do
primary_key :id
foreign_key :pool_id, :pools
String :name, null: false
String :better_legend, null: false
String :worse_legend, null: false
DateTime :created_at, null: false
DateTime :updated_at, null: false
end
create_table(:ratings) do
primary_key :id
foreign_key :axis_id, :axes
foreign_key :winner_id, :items
foreign_key :loser_id, :items
DateTime :created_at, null: false
DateTime :updated_at, null: false
end
create_table(:rankings) do
primary_key :id
foreign_key :axis_id, :axes
foreign_key :item_id, :items
Float :mu, null: false
Float :sigma, null: false
DateTime :created_at, null: false
DateTime :updated_at, null: false
end
end
end

@ -0,0 +1,19 @@
require "sequel"
Sequel::Model.plugin :timestamps, update_on_create: true
module RankKing
DB = Sequel.connect(ENV.fetch("DATABASE_URL"))
class Pool < Sequel::Model
end
class Item < Sequel::Model
end
class Axis < Sequel::Model(:axes)
end
def self.rate(axis:, winner:, loser:)
end
end

@ -0,0 +1,20 @@
require "minitest/autorun"
require "rank_king"
module RankKing
class TestRankKing < Minitest::Test
def test_rank_king
pool = Pool.create(name: "Ping Pong")
alice = Item.create(title: "Alice", body: "")
bob = Item.create(title: "Bob", body: "")
eve = Item.create(title: "Eve", body: "")
mallory = Item.create(title: "Mallory", body: "")
axis = Axis.create(name: "Rank", better_legend: "Better", worse_legend: "Worse")
RankKing.rate(axis:, winner: alice, loser: bob)
end
end
end
Loading…
Cancel
Save