<commit_before>module Persistize
  module ClassMethods
    def persistize(*args)
      options = args.pop if args.last.is_a?(Hash)
      
      args.each do |method|
        attribute = method.to_s.sub(/\?$/, '')
        
        original_method = :"_unpersistized_#{attribute}"
        update_method   = :"_update_#{attribute}"
        
        class_eval <<-RUBY, __FILE__, __LINE__ + 1
          alias #{original_method} #{method}                  # alias _unpersistized_full_name full_name
                                                              # 
          def #{method}                                       # def full_name
            if new_record? || changed?                        #   if new_record? || changed?
              #{original_method}                              #     _unpersistized_full_name
            else                                              #   else
              self[:#{attribute}]                             #     self[:full_name]
            end                                               #   end
          end                                                 # end
                                                              # 
          before_save :#{update_method}, :if => :changed?     # before_save :_update_full_name
                                                              # 
          def #{update_method}                                # def _update_full_name
            self[:#{attribute}] = #{original_method}          #   self[:full_name] = _unpersistized_full_name
            true # return true to avoid canceling the save    #   true
          end                                                 # end
                                                              # 
          def #{update_method}!                               # def _update_full_name!
            new_#{attribute} = #{original_method}             #   new_full_name = _unpersistized_full_name
            return if new_#{attribute} == self[:#{attribute}] #   return if new_full_name == self[:full_name]
            update_attribute :#{attribute}, new_#{attribute}  #   update_attribute :full_name, new_full_name 
          end                                                 # end
        RUBY

        if options && options[:depending_on]
          dependencies = [options[:depending_on]].flatten
          
          dependencies.each do |dependency|
            generate_callback(reflections[dependency], update_method)
          end
        end
        
      end
    end
    
    private
    
    def generate_callback(association, update_method)
      callback_name = :"#{update_method}_in_#{self.to_s.underscore.gsub(/\W/, '_')}_callback"<commit_msg>This is a temporal fix<commit_after>module Persistize
  mattr_accessor :performant
  self.performant = true

  module ClassMethods
    def persistize(*args)
      options = args.extract_options!

      performant = {:performant => ::Persistize.performant}.merge(options)[:performant]

      args.each do |method|
        attribute = method.to_s.sub(/\?$/, '')
        
        original_method = :"_unpersistized_#{attribute}"
        update_method   = :"_update_#{attribute}"
        
        class_eval <<-RUBY, __FILE__, __LINE__ + 1
          alias #{original_method} #{method}                    # alias _unpersistized_full_name full_name
                                                                #
          def #{method}                                         # def full_name
            if new_record? || changed?                          #   if new_record? || changed?
              #{original_method}                                #     _unpersistized_full_name
            else                                                #   else
              self[:#{attribute}]                               #     self[:full_name]
            end                                                 #   end
          end                                                   # end
                                                                #
          before_save :#{update_method}, :if => :changed?       # before_save :_update_full_name
                                                                #
          def #{update_method}                                  # def _update_full_name
            self[:#{attribute}] = #{original_method}            #   self[:full_name] = _unpersistized_full_name
            true # return true to avoid canceling the save      #   true
          end                                                   # end
                                                                #
          def #{update_method}!                                 # def _update_full_name!
            if #{performant}                                    #   if performant
              new_#{attribute} = #{original_method}             #     new_full_name = _unpersistized_full_name
              return if new_#{attribute} == self[:#{attribute}] #     return if new_full_name == self[:full_name]
              update_attribute :#{attribute}, new_#{attribute}  #     update_attribute :full_name, new_full_name
            else                                                #   else
              #{update_method}                                  #     _update_full_name
              save! if #{attribute}_changed?                    #     save! if full_name_changed?
            end                                                 #   end
          end                                                   # end
        RUBY

        if options && options[:depending_on]
          dependencies = [options[:depending_on]].flatten
          
          dependencies.each do |dependency|
            generate_callback(reflections[dependency], update_method)
          end
        end
        
      end
    end
    
    private
    
    def generate_callback(association, update_method)
      callback_name = :"#{update_method}_in_#{self.to_s.underscore.gsub(/\W/, '_')}_callback"
{'fraction_non_alphanumeric': 0.07608877023193726, 'fraction_numerical': 0.0003337226764558652, 'mean_word_length': 1.0100603621730382, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 56, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2834169', 'n_tokens_mistral': 1321, 'n_tokens_neox': 1309, 'n_words': 266}