<commit_before>module Spree
  Spree.user_class.class_eval do
    has_one :referral
    has_one :referred_record
    has_one :affiliate, through: :referred_record, foreign_key: :affiliate_id
    has_one :affiliate_record, class_name: 'ReferredRecord'

    attr_accessor :referral_code, :affiliate_code

    after_create :create_referral
    after_create :referral_affiliate_check

    def referred_user
      referred_record.referral.user rescue nil
    end
    
    def referral_count
      referral.referred_records.count
    end

    def referred?
      !referred_record.referral.user.nil? rescue false
    end

    def affiliate?
      !affiliate.nil? rescue false
    end

    private
      def referral_affiliate_check
        if !self.referral_code.nil?<commit_msg>Stops rescuing everything and uses try to catch<commit_after>module Spree
  Spree.user_class.class_eval do
    has_one :referral
    has_one :referred_record
    has_one :affiliate, through: :referred_record, foreign_key: :affiliate_id
    has_one :affiliate_record, class_name: ReferredRecord

    attr_accessor :referral_code, :affiliate_code

    after_create :create_referral
    after_create :referral_affiliate_check

    def referred_user
      referred_record.try(:referral).try(:user)
    end
    
    def referral_count
      referral.referred_records.count
    end

    def referred?
      !referred_record.try(:referral).try(:user).nil?
    end

    def affiliate?
      !affiliate.nil?
    end

    private
      def referral_affiliate_check
        if !self.referral_code.nil?
{'fraction_non_alphanumeric': 0.06021780909673286, 'fraction_numerical': 0.0, 'mean_word_length': 3.363128491620112, 'pattern_counts': {'":': 0, '<': 3, '<?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': '6940109', 'n_tokens_mistral': 520, 'n_tokens_neox': 504, 'n_words': 104}