<commit_before>class Identity < ApplicationRecord
  belongs_to :user

  # https://github.com/omniauth/omniauth/wiki/Managing-Multiple-Providers
  # https://www.sitepoint.com/rails-authentication-oauth-2-0-omniauth/
  # https://console.developers.google.com/apis/credentials?project=loom-development
  def self.by_omniauth(auth)
    identity = find_by(provider: auth["provider"], uid: auth["uid"]) || create_with_omniauth(auth)
    identity.user = find_corresponding_user(identity) if identity.user == nil
    identity.update_attribute(:image, auth["info"]["image"])
    identity.update_attribute(:first_name, auth["info"]["name"])
    identity
  end

  def full_name
    "#{last_name}, #{first_name}"
  end

  private
    def self.create_with_omniauth(auth)
      create! do |identity|
        name_parts = auth["info"]["name"].rpartition(" ")
        identity.provider = auth["provider"]
        identity.uid = auth["uid"]
        identity.first_name = name_parts.first
        identity.last_name = name_parts.last
        identity.nickname = extract_nickname(auth["info"])
        identity.email = auth["info"]["email"]
        identity.image = auth["info"]["image"]
        identity.user = find_corresponding_user(identity)
      end
    end
<commit_msg>Fallback for null names<commit_after>class Identity < ApplicationRecord
  belongs_to :user

  # https://github.com/omniauth/omniauth/wiki/Managing-Multiple-Providers
  # https://www.sitepoint.com/rails-authentication-oauth-2-0-omniauth/
  # https://console.developers.google.com/apis/credentials?project=loom-development
  def self.by_omniauth(auth)
    identity = find_by(provider: auth["provider"], uid: auth["uid"]) || create_with_omniauth(auth)
    identity.user = find_corresponding_user(identity) if identity.user == nil
    identity.update_attribute(:image, auth["info"]["image"])
    identity.update_attribute(:first_name, auth["info"]["name"])
    identity
  end

  def full_name
    "#{last_name}, #{first_name}"
  end

  private
    def self.create_with_omniauth(auth)
      create! do |identity|
        name_parts = (auth["info"]["name"] || FFaker::NameMX.full_name_no_prefix).rpartition(" ")
        identity.provider = auth["provider"]
        identity.uid = auth["uid"]
        identity.first_name = name_parts.first
        identity.last_name = name_parts.last
        identity.nickname = extract_nickname(auth["info"])
        identity.email = auth["info"]["email"]
        identity.image = auth["info"]["image"]
        identity.user = find_corresponding_user(identity)
      end
    end

{'fraction_non_alphanumeric': 0.13845553822152887, 'fraction_numerical': 0.0015600624024961, 'mean_word_length': 3.904397705544933, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 6, 'lorem ipsum': 0, 'www.': 2, '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': '2187993', 'n_tokens_mistral': 788, 'n_tokens_neox': 782, 'n_words': 120}