<commit_before>require 'active_support/core_ext/string/strip'

module RailsAdmin
  module Extensions
    module PaperTrail
      class VersionProxy
        def initialize(version, user_class = User)
          @version = version
          @user_class = user_class
        end

        def message
          @message = @version.event
          @version.respond_to?(:changeset) && @version.changeset.present? ? @message + ' [' + @version.changeset.to_a.collect { |c| c[0] + ' = ' + c[1][1].to_s }.join(', ') + ']' : @message
        end

        def created_at
          @version.created_at
        end

        def table
          @version.item_type
        end

        def username
          @user_class.find(@version.whodunnit).try(:email) rescue nil || @version.whodunnit
        end

        def item
          @version.item_id
        end
      end

      class AuditingAdapter
        COLUMN_MAPPING = {
          table: :item_type,
          username: :whodunnit,
          item: :item_id,
          created_at: :created_at,
          message: :event,
        }.freeze
        E_VERSION_MODEL_NOT_SET = <<-EOS.strip_heredoc.freeze
          Please set up PaperTrail's version model explicitly.

              config.audit_with :paper_trail, 'User', 'PaperTrail::Version'

          If you have configured a model to use a custom version class
          (https://github.com/paper-trail-gem/paper_trail#6a-custom-version-classes)<commit_msg>Fix the case where username is nil, not whodunnit<commit_after>require 'active_support/core_ext/string/strip'

module RailsAdmin
  module Extensions
    module PaperTrail
      class VersionProxy
        def initialize(version, user_class = User)
          @version = version
          @user_class = user_class
        end

        def message
          @message = @version.event
          @version.respond_to?(:changeset) && @version.changeset.present? ? @message + ' [' + @version.changeset.to_a.collect { |c| c[0] + ' = ' + c[1][1].to_s }.join(', ') + ']' : @message
        end

        def created_at
          @version.created_at
        end

        def table
          @version.item_type
        end

        def username
          (@user_class.find(@version.whodunnit).try(:email) rescue nil) || @version.whodunnit
        end

        def item
          @version.item_id
        end
      end

      class AuditingAdapter
        COLUMN_MAPPING = {
          table: :item_type,
          username: :whodunnit,
          item: :item_id,
          created_at: :created_at,
          message: :event,
        }.freeze
        E_VERSION_MODEL_NOT_SET = <<-EOS.strip_heredoc.freeze
          Please set up PaperTrail's version model explicitly.

              config.audit_with :paper_trail, 'User', 'PaperTrail::Version'

          If you have configured a model to use a custom version class
          (https://github.com/paper-trail-gem/paper_trail#6a-custom-version-classes)
{'fraction_non_alphanumeric': 0.09801912568306011, 'fraction_numerical': 0.00273224043715847, 'mean_word_length': 2.0352331606217615, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, 'https://': 2, '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': '3224877', 'n_tokens_mistral': 892, 'n_tokens_neox': 862, 'n_words': 193}