diff options
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/application_record.rb | 3 | ||||
-rw-r--r-- | app/models/puzzle.rb | 14 | ||||
-rw-r--r-- | app/models/score.rb | 7 | ||||
-rw-r--r-- | app/models/wittle/application_record.rb | 5 | ||||
-rw-r--r-- | app/models/wittle/puzzle.rb | 16 | ||||
-rw-r--r-- | app/models/wittle/score.rb | 9 |
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 @@ | |||
1 | class ApplicationRecord < ActiveRecord::Base | ||
2 | primary_abstract_class | ||
3 | end | ||
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 @@ | |||
1 | class 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 | ||
14 | end | ||
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 @@ | |||
1 | class 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 | ||
7 | end | ||
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 @@ | |||
1 | module Wittle | ||
2 | class ApplicationRecord < ActiveRecord::Base | ||
3 | self.abstract_class = true | ||
4 | end | ||
5 | end | ||
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 @@ | |||
1 | module 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 | ||
16 | end | ||
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 @@ | |||
1 | module 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 | ||
9 | end | ||