From be2a93525069de2dfa3c23b0c23e7a9f7ad4c03d Mon Sep 17 00:00:00 2001 From: Marius Peter Date: Sun, 29 Dec 2024 15:14:43 +0100 Subject: First commit. --- app/models/application_record.rb | 3 +++ app/models/concerns/.keep | 0 app/models/current.rb | 4 ++++ app/models/score.rb | 6 ++++++ app/models/scoring_criterium.rb | 9 +++++++++ app/models/session.rb | 3 +++ app/models/tartiflette.rb | 3 +++ app/models/user.rb | 6 ++++++ 8 files changed, 34 insertions(+) create mode 100644 app/models/application_record.rb create mode 100644 app/models/concerns/.keep create mode 100644 app/models/current.rb create mode 100644 app/models/score.rb create mode 100644 app/models/scoring_criterium.rb create mode 100644 app/models/session.rb create mode 100644 app/models/tartiflette.rb create mode 100644 app/models/user.rb (limited to 'app/models') 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 @@ +class ApplicationRecord < ActiveRecord::Base + primary_abstract_class +end diff --git a/app/models/concerns/.keep b/app/models/concerns/.keep new file mode 100644 index 0000000..e69de29 diff --git a/app/models/current.rb b/app/models/current.rb new file mode 100644 index 0000000..2bef56d --- /dev/null +++ b/app/models/current.rb @@ -0,0 +1,4 @@ +class Current < ActiveSupport::CurrentAttributes + attribute :session + delegate :user, to: :session, allow_nil: true +end diff --git a/app/models/score.rb b/app/models/score.rb new file mode 100644 index 0000000..5147ce0 --- /dev/null +++ b/app/models/score.rb @@ -0,0 +1,6 @@ +class Score < ApplicationRecord + belongs_to :tartiflette + belongs_to :scoring_criterium + + validates :value, presence: true, inclusion: { in: 1..5 } +end diff --git a/app/models/scoring_criterium.rb b/app/models/scoring_criterium.rb new file mode 100644 index 0000000..a94ad77 --- /dev/null +++ b/app/models/scoring_criterium.rb @@ -0,0 +1,9 @@ +class ScoringCriterium < ApplicationRecord + has_many :scores, dependent: :destroy + + validates :name, :category, presence: true + + def self.grouped_by_category + ScoringCriterium.all.group_by(&:category) + end +end diff --git a/app/models/session.rb b/app/models/session.rb new file mode 100644 index 0000000..cf376fb --- /dev/null +++ b/app/models/session.rb @@ -0,0 +1,3 @@ +class Session < ApplicationRecord + belongs_to :user +end diff --git a/app/models/tartiflette.rb b/app/models/tartiflette.rb new file mode 100644 index 0000000..4abfe74 --- /dev/null +++ b/app/models/tartiflette.rb @@ -0,0 +1,3 @@ +class Tartiflette < ApplicationRecord + has_many :scores +end diff --git a/app/models/user.rb b/app/models/user.rb new file mode 100644 index 0000000..c88d5b0 --- /dev/null +++ b/app/models/user.rb @@ -0,0 +1,6 @@ +class User < ApplicationRecord + has_secure_password + has_many :sessions, dependent: :destroy + + normalizes :email_address, with: ->(e) { e.strip.downcase } +end -- cgit v1.2.3