<commit_before>class Reserver
  include ActiveModel::Model
  # Callbacks
  define_model_callbacks :reservation_save
  # Keycard Include
  include Keycards::ReserverModule
  # Validations
  validates :start_time, :end_time, :room, :reserver_onid, :user_onid, :presence => true
  validate :user_not_nil
  validate :start_time_less_than_end_time
  validate :reservation_not_in_past
  validate :room_is_persisted
  validate :time_is_available
  validate :duration_correct
  validate :authorized_to_reserve
  validate :concurrency_limit
  validate :append_reservation_errors
  validate :day_limit_applied

  delegate :reserver, :user, :reserver_onid, :user_onid, :room_id, :room, :start_time, :end_time, :description, :key_card, :decorate, :to => :reservation
  delegate :start_time=, :end_time=, :room=, :reserver=, :user=, :reserver_onid=, :user_onid=, :to => :reservation
  attr_accessor :key_card_key
  attr_reader :reservation

  delegate :as_json, :read_attribute_for_serialization, :to => :reservation
  after_reservation_save :send_email


  def self.reflect_on_association(association)
    Reservation.reflect_on_association(association)
  end
  def initialize(attributes = {},options={})
    @options = options
    if attributes.kind_of?(Reservation)
      @reservation = attributes
      return
    end
    self.key_card_key = attributes.delete(:key_card_key)
    @reservation ||= Reservation.new
    @reservation.attributes = attributes
  end

  def email_method
    @email_method ||= begin
      return @options[:email_method] unless @options[:email_method].blank?
      if reservation.versions.size > 1
        :update_email
      else
        :reservation_email
      end
    end
  end

  def save
    return false unless valid?
    @reservation ||= Reservation.new

    run_callbacks :reservation_save do
      @reservation.save
    end
  end

  def persisted?
    reservation.persisted?
  end

  def reservation
    @reservation || Reservation.new
  end

  private

  def send_email
    return if @options[:ignore_email]
    unless user.email.blank?
      ReservationMailer.delay.send(email_method, reservation, user.decorate)
    end
  end
<commit_msg>Pushed fix for when versioning is turned off in specs.<commit_after>class Reserver
  include ActiveModel::Model
  # Callbacks
  define_model_callbacks :reservation_save
  # Keycard Include
  include Keycards::ReserverModule
  # Validations
  validates :start_time, :end_time, :room, :reserver_onid, :user_onid, :presence => true
  validate :user_not_nil
  validate :start_time_less_than_end_time
  validate :reservation_not_in_past
  validate :room_is_persisted
  validate :time_is_available
  validate :duration_correct
  validate :authorized_to_reserve
  validate :concurrency_limit
  validate :append_reservation_errors
  validate :day_limit_applied

  delegate :reserver, :user, :reserver_onid, :user_onid, :room_id, :room, :start_time, :end_time, :description, :key_card, :decorate, :to => :reservation
  delegate :start_time=, :end_time=, :room=, :reserver=, :user=, :reserver_onid=, :user_onid=, :to => :reservation
  attr_accessor :key_card_key
  attr_reader :reservation

  delegate :as_json, :read_attribute_for_serialization, :to => :reservation
  after_reservation_save :send_email


  def self.reflect_on_association(association)
    Reservation.reflect_on_association(association)
  end
  def initialize(attributes = {},options={})
    @options = options
    if attributes.kind_of?(Reservation)
      @reservation = attributes
      @options[:email_method] = :update_email if @reservation.persisted?
      return
    end
    self.key_card_key = attributes.delete(:key_card_key)
    @reservation ||= Reservation.new
    @reservation.attributes = attributes
  end

  def save
    return false unless valid?
    @reservation ||= Reservation.new

    run_callbacks :reservation_save do
      @reservation.save
    end
  end

  def persisted?
    reservation.persisted?
  end

  def reservation
    @reservation || Reservation.new
  end

  private

  def send_email
    return if @options[:ignore_email]
    unless user.email.blank?
      ReservationMailer.delay.send(email_method, reservation, user.decorate)
    end
  end

  def email_method
    @email_method ||= begin
      return @options[:email_method] unless @options[:email_method].blank?
      if reservation.versions.size > 1
        :update_email
      else
        :reservation_email
      end
    end
  end

{'fraction_non_alphanumeric': 0.08415841584158416, 'fraction_numerical': 0.00045004500450045, 'mean_word_length': 4.285374554102259, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, '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': '1426113', 'n_tokens_mistral': 1447, 'n_tokens_neox': 1395, 'n_words': 313}