<commit_before>class User < ActiveRecord::Base
  before_create :set_auth_token

  # Include default devise modules. Others available are:
  # :confirmable, :lockable, :timeoutable and :omniauthable
  devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :trackable, :validatable
  has_one :garage, foreign_key: "owner_id"
  enum role: [:admin, :country_manager, :owner]

  ADMIN = roles[:admin]
  COUNTRY_MANAGER = roles[:country_manager]
  OWNER = roles[:owner]

  after_initialize :set_default_role, :if => :new_record?

  def set_default_role
    self.role ||= :owner
  end

private

  def set_auth_token
    return if auth_token.present?
    self.auth_token = generate_auth_token
  end


  def generate_auth_token
    loop do
      token = SecureRandom.hex
      break token unless self.class.exists?(auth_token: token)
    end
  end
end
<commit_msg>adding new role for API users<commit_after>class User < ActiveRecord::Base
  before_create :set_auth_token

  # Include default devise modules. Others available are:
  # :confirmable, :lockable, :timeoutable and :omniauthable
  devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :trackable, :validatable
  has_one :garage, foreign_key: "owner_id"
  enum role: [:admin, :country_manager, :owner, :api]

  ADMIN = roles[:admin]
  COUNTRY_MANAGER = roles[:country_manager]
  OWNER = roles[:owner]
  API = roles[:api]

  after_initialize :set_default_role, :if => :new_record?

  def set_default_role
    self.role ||= :owner
  end

private

  def set_auth_token
    return if auth_token.present?
    self.auth_token = generate_auth_token
  end


  def generate_auth_token
    loop do
      token = SecureRandom.hex
      break token unless self.class.exists?(auth_token: token)
    end
  end
end

{'fraction_non_alphanumeric': 0.0881057268722467, 'fraction_numerical': 0.0, 'mean_word_length': 4.191428571428571, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '4500063', 'n_tokens_mistral': 609, 'n_tokens_neox': 580, 'n_words': 150}