<commit_before>module AbAdmin
  module Models
    module Track

      extend ActiveSupport::Concern

      included do
        belongs_to :trackable, polymorphic: true
        belongs_to :owner, class_name: 'User'
        belongs_to :user, class_name: 'User'

        serialize :parameters, Hash
        serialize :trackable_changes, Hash

        before_create :make_trackable, if: :trackable

        class_attribute :tracking_enabled
        self.tracking_enabled = true

        alias_method :tracking_enabled?, :tracking_enabled

        scope :recently, -> { order('id DESC') }
      end

      def action_title(params = {})
        parts = key.split('.')
        lookups = []
        if parts.length == 2
          lookups << [parts[0], 'actions', parts[1], 'title']
          lookups << [parts[0], 'actions', parts[1]]
          lookups << ['actions', parts[1], 'title']
        else
          lookups << ['actions', key, 'title']
          lookups << ['actions', key]
        end
        lookups.map!{|l| l.join('.').to_sym }
        lookups << key

        I18n.t(lookups.shift, (parameters.merge(params) || {}).merge(scope: :admin, default: lookups))
      end

      def trackable_changed_attrs
        return unless trackable
        trackable_changes.keys.map { |attr| trackable_han(attr) }.join(', ')
      end

      def trackable_han(attr)
        attr_s = attr.to_s
        trackable.class.han attr_s =~ /_ids$/ ? attr_s.sub(/_ids$/, '').pluralize : attr_s
      end

      private

      def make_trackable
        self.name ||= trackable.han
        self.trackable_changes = trackable.changes.except(:updated_at)
      end

    end
  end
end<commit_msg>Truncate name for track<commit_after>module AbAdmin
  module Models
    module Track

      extend ActiveSupport::Concern

      included do
        belongs_to :trackable, polymorphic: true
        belongs_to :owner, class_name: 'User'
        belongs_to :user, class_name: 'User'

        serialize :parameters, Hash
        serialize :trackable_changes, Hash

        before_create :make_trackable, if: :trackable

        class_attribute :tracking_enabled
        self.tracking_enabled = true

        alias_method :tracking_enabled?, :tracking_enabled

        scope :recently, -> { order('id DESC') }
      end

      def action_title(params = {})
        parts = key.split('.')
        lookups = []
        if parts.length == 2
          lookups << [parts[0], 'actions', parts[1], 'title']
          lookups << [parts[0], 'actions', parts[1]]
          lookups << ['actions', parts[1], 'title']
        else
          lookups << ['actions', key, 'title']
          lookups << ['actions', key]
        end
        lookups.map!{|l| l.join('.').to_sym }
        lookups << key

        I18n.t(lookups.shift, (parameters.merge(params) || {}).merge(scope: :admin, default: lookups))
      end

      def trackable_changed_attrs
        return unless trackable
        trackable_changes.keys.map { |attr| trackable_han(attr) }.join(', ')
      end

      def trackable_han(attr)
        attr_s = attr.to_s
        trackable.class.han attr_s =~ /_ids$/ ? attr_s.sub(/_ids$/, '').pluralize : attr_s
      end

      private

      def make_trackable
        self.name ||= trackable.han.first(250)
        self.trackable_changes = trackable.changes.except(:updated_at)
      end

    end
  end
end
{'fraction_non_alphanumeric': 0.12087912087912088, 'fraction_numerical': 0.005643005643005643, 'mean_word_length': 2.2730806608357628, 'pattern_counts': {'":': 0, '<': 27, '<?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': '747930', 'n_tokens_mistral': 1059, 'n_tokens_neox': 1006, 'n_words': 236}