commit b26b3cd908ad97ef989e36512ccdb80fec304a08 Author: Alpha Chen Date: Tue Nov 15 12:44:20 2022 -0800 add skeleton for models diff --git a/.ruby-version b/.ruby-version new file mode 100644 index 0000000..8c50098 --- /dev/null +++ b/.ruby-version @@ -0,0 +1 @@ +3.1 diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..93c7b8a --- /dev/null +++ b/Gemfile @@ -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 diff --git a/Gemfile.lock b/Gemfile.lock new file mode 100644 index 0000000..214e4e9 --- /dev/null +++ b/Gemfile.lock @@ -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 diff --git a/Rakefile b/Rakefile new file mode 100644 index 0000000..83beed0 --- /dev/null +++ b/Rakefile @@ -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 diff --git a/Steepfile b/Steepfile new file mode 100644 index 0000000..a0cb3e8 --- /dev/null +++ b/Steepfile @@ -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 diff --git a/db/migrations/001_init.rb b/db/migrations/001_init.rb new file mode 100644 index 0000000..57e23ef --- /dev/null +++ b/db/migrations/001_init.rb @@ -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 diff --git a/lib/rank_king.rb b/lib/rank_king.rb new file mode 100644 index 0000000..a1011dd --- /dev/null +++ b/lib/rank_king.rb @@ -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 diff --git a/test/test_rank_king.rb b/test/test_rank_king.rb new file mode 100644 index 0000000..418b639 --- /dev/null +++ b/test/test_rank_king.rb @@ -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