<commit_before>class User < ActiveRecord::Base
  # Include default devise modules. Others available are:
  # :confirmable, :lockable, :timeoutable and :omniauthable
  devise :database_authenticatable, :trackable, :rememberable

  has_many :results
  has_many :arenas

  has_many :feedbacks
  has_many :decks

  validates_presence_of :username

  has_many :notification_reads
  has_many :read_notifications, class_name: 'Notification', through: :notification_reads, source: :notification

  before_save :ensure_api_authentication_token

  def unread_notifications
    Notification.where.not(id: read_notifications)
                .where.not(hidden: true)
  end

  # One Time Auth
  def regenerate_one_time_authentication_token
    self.one_time_authentication_token = loop do
      token = Devise.friendly_token
      break token unless self.class.where(one_time_authentication_token: token).first
    end
  end

  def regenerate_one_time_authentication_token!
    regenerate_one_time_authentication_token.tap { save }
  end

  def check_and_redeem_one_time_authentication_token(token)
    if Devise.secure_compare(one_time_authentication_token, token)
      regenerate_one_time_authentication_token!
      true
    else
      false
    end
  end

  # API Token
  def regenerate_api_authentication_token
    self.api_authentication_token = loop do
      token = Devise.friendly_token
      break token unless self.class.where(api_authentication_token: token).first
    end
  end

  def ensure_api_authentication_token
    if api_authentication_token.blank?
      regenerate_api_authentication_token
    end
  end
end<commit_msg>Explicitness<commit_after>class User < ActiveRecord::Base
  # Include default devise modules. Others available are:
  # :confirmable, :lockable, :timeoutable and :omniauthable
  devise :database_authenticatable, :trackable, :rememberable

  has_many :results
  has_many :arenas

  has_many :feedbacks
  has_many :decks

  validates_presence_of :username

  has_many :notification_reads
  has_many :read_notifications, class_name: 'Notification', through: :notification_reads, source: :notification

  before_save :ensure_api_authentication_token

  def unread_notifications
    Notification.where.not(id: read_notifications)
                .where.not(hidden: true)
  end

  # One Time Auth
  def regenerate_one_time_authentication_token
    self.one_time_authentication_token = loop do
      token = Devise.friendly_token
      break token unless self.class.where(one_time_authentication_token: token).exists?
    end
  end

  def regenerate_one_time_authentication_token!
    regenerate_one_time_authentication_token.tap { save }
  end

  def check_and_redeem_one_time_authentication_token(token)
    if Devise.secure_compare(one_time_authentication_token, token)
      regenerate_one_time_authentication_token!
      true
    else
      false
    end
  end

  # API Token
  def regenerate_api_authentication_token
    self.api_authentication_token = loop do
      token = Devise.friendly_token
      break token unless self.class.where(api_authentication_token: token).exists?
    end
  end

  def ensure_api_authentication_token
    if api_authentication_token.blank?
      regenerate_api_authentication_token
    end
  end
end
{'fraction_non_alphanumeric': 0.052163240257747774, 'fraction_numerical': 0.0, 'mean_word_length': 4.3884297520661155, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '7512926', 'n_tokens_mistral': 1017, 'n_tokens_neox': 972, 'n_words': 209}