<commit_before>class Appointment < ActiveRecord::Base
  belongs_to :mentor, class_name: 'User'
  belongs_to :student, class_name: 'User'
  has_many :reviews
  has_and_belongs_to_many :topics

  validates :start_time, :length, :phase, presence: true
  validate :cannot_end_before_it_starts, :cannot_start_in_the_past, :cannot_overlap_existing_user_appointment

def end_time
  start_time + length.minutes
end

def cannot_end_before_it_starts
  if start_time - end_time < 0
    errors.add(:end_time, "cannot be before the start time.")
  end
end

def cannot_start_in_the_past
  if start_time < DateTime.now
    errors.add(:start_time, "cannot be in the past.")
  end
end

def cannot_overlap_existing_user_appointment
  potential_conflicts = User.find(student_id || mentor_id).appointments
  if potential_conflicts.any?{
    |appt| start_time >= appt.start_time && start_time < appt.end_time }
    errors.add(:start_time, "overlaps with one of your existing commitments.")
  elsif potential_conflicts.any?{ |appt| end_time > appt.start_time && end_time <= appt.end_time}
      errors.add(:end_time, "overlaps with one of your existing commitments.")
  end
end

end
<commit_msg>Add virtual attribute methods for status on appointment<commit_after>class Appointment < ActiveRecord::Base
  belongs_to :mentor, class_name: 'User'
  belongs_to :student, class_name: 'User'
  has_many :reviews
  has_and_belongs_to_many :topics

  validates :start_time, :length, :phase, presence: true
  validate :cannot_end_before_it_starts, :cannot_start_in_the_past, :cannot_overlap_existing_user_appointment

def end_time
  start_time + length.minutes
end

def open?
  !student_id && !self.complete?
end

def accepted?
  !self.open?
end

def complete?
  self.end_time < DateTime.now
end

private

def cannot_end_before_it_starts
  if start_time - self.end_time < 0
    errors.add(:end_time, "cannot be before the start time.")
  end
end

def cannot_start_in_the_past
  if start_time < DateTime.now
    errors.add(:start_time, "cannot be in the past.")
  end
end

def cannot_overlap_existing_user_appointment
  potential_conflicts = User.find(student_id || mentor_id).appointments
  if potential_conflicts.any?{
    |appt| start_time >= appt.start_time && start_time < appt.end_time }
    errors.add(:start_time, "overlaps with one of your existing commitments.")
  elsif potential_conflicts.any?{ |appt| self.end_time > appt.start_time && self.end_time <= appt.end_time}
      errors.add(:end_time, "overlaps with one of your existing commitments.")
  end
end

end

{'fraction_non_alphanumeric': 0.08651199370821865, 'fraction_numerical': 0.0007864726700747149, 'mean_word_length': 5.115384615384615, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1355750', 'n_tokens_mistral': 898, 'n_tokens_neox': 869, 'n_words': 218}