Total Complexity | 3 |
Total Lines | 22 |
Duplicated Lines | 0 % |
Changes | 2 | ||
Bugs | 0 | Features | 1 |
1 | # frozen_string_literal: true |
||
4 | class Participant < ApplicationRecord |
||
5 | belongs_to :user, optional: true |
||
6 | validates :email, presence: true, 'valid_email_2/email': true |
||
7 | has_one :journal, inverse_of: :participant, dependent: :destroy |
||
8 | has_many :survey_participants, inverse_of: :participant, dependent: :destroy |
||
9 | has_many :surveys, through: :survey_participants |
||
10 | has_many :study_participants, inverse_of: :participant, dependent: :destroy |
||
11 | has_many :studies, through: :study_participants |
||
12 | validates :journal, presence: true |
||
13 | |||
14 | after_initialize :create_journal |
||
15 | |||
16 | def to_s |
||
17 | "#{identifier} #{email}".strip |
||
18 | end |
||
19 | |||
20 | private |
||
21 | |||
22 | def create_journal |
||
23 | self.journal ||= Journal.new(participant: self, name: Time.now.to_s) if new_record? |
||
24 | end |
||
25 | end |
||
26 |