about summary refs log tree commit diff stats
path: root/app/models
diff options
context:
space:
mode:
authorStar Rauchenberger <fefferburbia@gmail.com>2023-11-30 13:29:08 -0500
committerStar Rauchenberger <fefferburbia@gmail.com>2023-11-30 13:29:08 -0500
commit0929719a845897cc8567cf972e07a69a71f0fa6f (patch)
tree2b6f69c1d906abb6e0abf8a0f1d51725bc78087d /app/models
parent01c1947537e4e23ded0c16812a7cd9d49ad88356 (diff)
downloadwittle-0929719a845897cc8567cf972e07a69a71f0fa6f.tar.gz
wittle-0929719a845897cc8567cf972e07a69a71f0fa6f.tar.bz2
wittle-0929719a845897cc8567cf972e07a69a71f0fa6f.zip
Migrate to a full rails app
Diffstat (limited to 'app/models')
-rw-r--r--app/models/application_record.rb3
-rw-r--r--app/models/puzzle.rb14
-rw-r--r--app/models/score.rb7
-rw-r--r--app/models/wittle/application_record.rb5
-rw-r--r--app/models/wittle/puzzle.rb16
-rw-r--r--app/models/wittle/score.rb9
6 files changed, 24 insertions, 30 deletions
diff --git a/app/models/application_record.rb b/app/models/application_record.rb new file mode 100644 index 0000000..b63caeb --- /dev/null +++ b/app/models/application_record.rb
@@ -0,0 +1,3 @@
1class ApplicationRecord < ActiveRecord::Base
2 primary_abstract_class
3end
diff --git a/app/models/puzzle.rb b/app/models/puzzle.rb new file mode 100644 index 0000000..4f57d9c --- /dev/null +++ b/app/models/puzzle.rb
@@ -0,0 +1,14 @@
1class Puzzle < ApplicationRecord
2 extend Enumerize
3
4 has_many :scores
5
6 validates :data, presence: true
7
8 validates :category, presence: true
9 enumerize :category, in: [:normal, :hard, :expert], scope: :shallow
10
11 def latest?
12 Puzzle.where(category: category).order(created_at: :desc).first.id == id
13 end
14end
diff --git a/app/models/score.rb b/app/models/score.rb new file mode 100644 index 0000000..1958389 --- /dev/null +++ b/app/models/score.rb
@@ -0,0 +1,7 @@
1class Score < ApplicationRecord
2 belongs_to :puzzle
3
4 validates :name, presence: true
5 validates :ip, presence: true
6 validates_uniqueness_of :name, scope: :puzzle_id
7end
diff --git a/app/models/wittle/application_record.rb b/app/models/wittle/application_record.rb deleted file mode 100644 index be1dfe5..0000000 --- a/app/models/wittle/application_record.rb +++ /dev/null
@@ -1,5 +0,0 @@
1module Wittle
2 class ApplicationRecord < ActiveRecord::Base
3 self.abstract_class = true
4 end
5end
diff --git a/app/models/wittle/puzzle.rb b/app/models/wittle/puzzle.rb deleted file mode 100644 index f9009bc..0000000 --- a/app/models/wittle/puzzle.rb +++ /dev/null
@@ -1,16 +0,0 @@
1module Wittle
2 class Puzzle < ApplicationRecord
3 extend Enumerize
4
5 has_many :scores
6
7 validates :data, presence: true
8
9 validates :category, presence: true
10 enumerize :category, in: [:normal, :hard, :expert], scope: :shallow
11
12 def latest?
13 Puzzle.where(category: category).order(created_at: :desc).first.id == id
14 end
15 end
16end
diff --git a/app/models/wittle/score.rb b/app/models/wittle/score.rb deleted file mode 100644 index 54d2b89..0000000 --- a/app/models/wittle/score.rb +++ /dev/null
@@ -1,9 +0,0 @@
1module Wittle
2 class Score < ApplicationRecord
3 belongs_to :puzzle
4
5 validates :name, presence: true
6 validates :ip, presence: true
7 validates_uniqueness_of :name, scope: :puzzle_id
8 end
9end