diff options
author | David Gay <david@davidgay.org> | 2023-11-02 18:30:14 -0400 |
---|---|---|
committer | David Gay <david@davidgay.org> | 2023-11-02 18:30:14 -0400 |
commit | f353175922bf855f732ee0fb8e976167d001a92b (patch) | |
tree | 4f4a7480b7ec6ee926ca61ff762735681c8c0104 /app/models/run.rb | |
parent | 755bfe6da54ed67a759f26ba4c328a2e8175b2f6 (diff) |
Checkout a run to the creator after it's created
Diffstat (limited to 'app/models/run.rb')
-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 |