diff options
Diffstat (limited to 'app')
-rw-r--r-- | app/models/run.rb | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/app/models/run.rb b/app/models/run.rb index 023202b..a763654 100644 --- a/app/models/run.rb +++ b/app/models/run.rb @@ -5,9 +5,24 @@ class Run < ApplicationRecord validates :title, presence: true + after_create :checkout_to_creator + def checked_in? + checkpoints.where.not(kind: :comment).last.checkin? + end + + def checked_out_user last_checkpoint = checkpoints.where.not(kind: :comment).last - # If there are no non-comment checkpoints, then the run was never checked in. - last_checkpoint.nil? ? false : last_checkpoint.checkin? + last_checkpoint.checkout? ? last_checkpoint.user : nil + end + + def last_save_file + checkpoints.except(save_file: nil).last&.save_file + end + +private + + def checkout_to_creator + checkpoints.create(user:, kind: :checkout) end end |