<commit_before>class CellPhone < ActiveRecord::Base
  # TODO(chase): add uniqueness to validation: {scope: :user_id}
  validates :number, presence: true,
                     format: {with: /\A\+\d{11}\z/,
                              message: 'is invalid, please format like ' +
                                       '+18598675309'}

  before_create :set_random_auth_code
  after_update :reset_verification!, if: :verified_and_changed?
  after_save :send_auth_code, if: :unverified_and_new_auth_code?
  before_save :set_random_auth_code, if: :number_changed?

  def verified_and_changed?
    number_changed? && verified?
  end

  def reset_verification!
    update_attribute(:verified, false)
  end

  def self.generate_auth_code
    '%05d' % SecureRandom.random_number(99999)
  end

  def verified!
    update_attribute(:verified, true)
  end

  private

  def set_random_auth_code<commit_msg>going to need this method too<commit_after>class CellPhone < ActiveRecord::Base
  # TODO(chase): add uniqueness to validation: {scope: :user_id}
  validates :number, presence: true,
                     format: {with: /\A\+\d{11}\z/,
                              message: 'is invalid, please format like ' +
                                       '+18598675309'}

  before_create :set_random_auth_code
  after_update :reset_verification!, if: :verified_and_changed?
  after_save :send_auth_code, if: :unverified_and_new_auth_code?
  before_save :set_random_auth_code, if: :number_changed?

  def verified_and_changed?
    number_changed? && verified?
  end

  def reset_verification!
    update_attribute(:verified, false)
  end

  def self.generate_auth_code
    '%05d' % SecureRandom.random_number(99999)
  end

  def verified!
    update_attribute(:verified, true)
  end

  def unverified?
    !verified?
  end

  private

  def set_random_auth_code
{'fraction_non_alphanumeric': 0.0891891891891892, 'fraction_numerical': 0.021621621621621623, 'mean_word_length': 3.050328227571116, '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': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4086264', 'n_tokens_mistral': 625, 'n_tokens_neox': 575, 'n_words': 130}